Skip to content

Commit 23ac06e

Browse files
committed
Fix a bug in link re-writing
In a regex, `.` means `[0-9a-zA-Z]`, not a period character. This means that this regex worked, unless a link anchor contained `md` inside of it. This fixes the regex to match a literal period. Reported by @ehuss in #866 (comment)
1 parent 2ddbb37 commit 23ac06e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/utils/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn id_from_content(content: &str) -> String {
6969
fn adjust_links<'a>(event: Event<'a>, with_base: &str) -> Event<'a> {
7070
lazy_static! {
7171
static ref HTTP_LINK: Regex = Regex::new("^https?://").unwrap();
72-
static ref MD_LINK: Regex = Regex::new("(?P<link>.*).md(?P<anchor>#.*)?").unwrap();
72+
static ref MD_LINK: Regex = Regex::new(r"(?P<link>.*)\.md(?P<anchor>#.*)?").unwrap();
7373
}
7474

7575
match event {
@@ -230,6 +230,12 @@ mod tests {
230230
render_markdown("[example_anchor](example.md#anchor)", false),
231231
"<p><a href=\"example.html#anchor\">example_anchor</a></p>\n"
232232
);
233+
234+
// this anchor contains 'md' inside of it
235+
assert_eq!(
236+
render_markdown("[phantom data](foo.html#phantomdata)", false),
237+
"<p><a href=\"foo.html#phantomdata\">phantom data</a></p>\n"
238+
);
233239
}
234240

235241
#[test]

0 commit comments

Comments
 (0)