From d665732056d5fb96fdfe085ab65df9a5771b4c22 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Sun, 3 May 2020 14:42:22 +0200 Subject: [PATCH 1/2] Links preprocessor: test links with special characters --- src/preprocess/links.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index 0b593e30..891769a3 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -451,6 +451,24 @@ mod tests { ); } + #[test] + fn test_find_links_with_special_characters() { + let s = "Some random text with {{#playpen foo-bar\\baz/_c++.rs}}..."; + + let res = find_links(s).collect::>(); + println!("\nOUTPUT: {:?}\n", res); + + assert_eq!( + res, + vec![Link { + start_index: 22, + end_index: 54, + link_type: LinkType::Playpen(PathBuf::from("foo-bar\\baz/_c++.rs"), vec![]), + link_text: "{{#playpen foo-bar\\baz/_c++.rs}}", + },] + ); + } + #[test] fn test_find_links_with_range() { let s = "Some random text with {{#include file.rs:10:20}}..."; From b1cf3f117d3d98ff75f489fc157fa3632247b595 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Sun, 3 May 2020 14:50:03 +0200 Subject: [PATCH 2/2] Links preprocessor: support pluses in file paths --- src/preprocess/links.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index 891769a3..408873aa 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -364,14 +364,14 @@ fn find_links(contents: &str) -> LinkIter<'_> { // r"\\\{\{#.*\}\}|\{\{#([a-zA-Z0-9]+)\s*([a-zA-Z0-9_.\-:/\\\s]+)\}\}")?; lazy_static! { static ref RE: Regex = Regex::new( - r"(?x) # insignificant whitespace mode - \\\{\{\#.*\}\} # match escaped link - | # or - \{\{\s* # link opening parens and whitespace - \#([a-zA-Z0-9_]+) # link type - \s+ # separating whitespace - ([a-zA-Z0-9\s_.\-:/\\]+) # link target path and space separated properties - \s*\}\} # whitespace and link closing parens" + r"(?x) # insignificant whitespace mode + \\\{\{\#.*\}\} # match escaped link + | # or + \{\{\s* # link opening parens and whitespace + \#([a-zA-Z0-9_]+) # link type + \s+ # separating whitespace + ([a-zA-Z0-9\s_.\-:/\\\+]+) # link target path and space separated properties + \s*\}\} # whitespace and link closing parens" ) .unwrap(); }