From 501c8b047a178c71b3f50f98475f6327f6a41142 Mon Sep 17 00:00:00 2001 From: Jaeseok Lee Date: Tue, 19 Aug 2025 22:50:14 +0900 Subject: [PATCH 1/2] add md_empty_link_parsing test with bug case --- src/vault/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/vault/mod.rs b/src/vault/mod.rs index 06ab07f4..21876be0 100644 --- a/src/vault/mod.rs +++ b/src/vault/mod.rs @@ -2013,6 +2013,51 @@ mod vault_tests { assert_eq!(parsed, expected); } + #[test] + fn md_empty_link_parsing() { + let text = "[]()"; + let parsed = Reference::new(text, "test.md").collect_vec(); + + let expected = vec![Reference::MDFileLink(ReferenceData { + reference_text: "test.md".into(), + display_text: Some("".into()), + range: Range { + start: Position { + line: 0, + character: 0, + }, + end: Position { + line: 0, + character: 4, + }, + } + .into(), + })]; + + assert_eq!(parsed, expected); + + let text = "[]()\n)"; + let parsed = Reference::new(text, "test.md").collect_vec(); + + let expected = vec![Reference::MDFileLink(ReferenceData { + reference_text: "test.md".into(), + display_text: Some("".into()), + range: Range { + start: Position { + line: 0, + character: 0, + }, + end: Position { + line: 0, + character: 4, + }, + } + .into(), + })]; + + assert_eq!(parsed, expected); + } + #[test] fn footnote_link_parsing() { let text = "This is a footnote[^1] From f108991cd07f50619b621ad861a57b61409fc106 Mon Sep 17 00:00:00 2001 From: Jaeseok Lee Date: Tue, 19 Aug 2025 22:54:36 +0900 Subject: [PATCH 2/2] fix: md link should not contain parentheses --- src/vault/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vault/mod.rs b/src/vault/mod.rs index 21876be0..3e2246b0 100644 --- a/src/vault/mod.rs +++ b/src/vault/mod.rs @@ -744,7 +744,7 @@ impl Reference { }); static MD_LINK_RE: Lazy = Lazy::new(|| { - Regex::new(r"\[(?[^\[\]\.]*?)\]\((\.?\/)?[^\[\]\|\.\#<>]+?)?(?\.[^\# <>]+?)?(\#(?[^\[\]\.\|<>]+?))?>?\)") + Regex::new(r"\[(?[^\[\]\.]*?)\]\((\.?\/)?[^\[\]\|\.\#<>()]+?)?(?\.[^\# <>]+?)?(\#(?[^\[\]\.\|<>()]+?))?>?\)") .expect("MD Link Not Constructing") }); // [display](relativePath)