From e6fc611b583903895cfd3f86d0077a56991a369f Mon Sep 17 00:00:00 2001 From: Nick Groenen Date: Sun, 10 Jan 2021 19:43:28 +0100 Subject: [PATCH] fix: find uppercased notes when referenced with lowercase This commit fixes a bug where, if a note contained uppercase characters (for example `Note.md`) but was referred to using lowercase `(`[[note]]`), that note would not be found. --- src/lib.rs | 5 +++-- tests/testdata/expected/main-samples/obsidian-wikilinks.md | 2 ++ tests/testdata/input/main-samples/Uppercased-note.md | 0 tests/testdata/input/main-samples/obsidian-wikilinks.md | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 tests/testdata/input/main-samples/Uppercased-note.md diff --git a/src/lib.rs b/src/lib.rs index 991f2c4..bfae1ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -586,10 +586,11 @@ fn lookup_filename_in_vault<'a>( // sentence even if the note is capitalized for example) so we also try a case-insensitive // lookup. vault_contents.iter().find(|path| { + let path_lowered = PathBuf::from(path.to_string_lossy().to_lowercase()); path.ends_with(&filename) - || path.ends_with(&filename.to_lowercase()) + || path_lowered.ends_with(&filename.to_lowercase()) || path.ends_with(format!("{}.md", &filename)) - || path.ends_with(format!("{}.md", &filename.to_lowercase())) + || path_lowered.ends_with(format!("{}.md", &filename.to_lowercase())) }) } diff --git a/tests/testdata/expected/main-samples/obsidian-wikilinks.md b/tests/testdata/expected/main-samples/obsidian-wikilinks.md index a77822d..a27bd59 100644 --- a/tests/testdata/expected/main-samples/obsidian-wikilinks.md +++ b/tests/testdata/expected/main-samples/obsidian-wikilinks.md @@ -6,6 +6,8 @@ Link to [pure-markdown-examples > Heading 1](pure-markdown-examples.md#heading-1 Link to [pure markdown examples](pure-markdown-examples.md#heading-1). +Link to [uppercased-note](Uppercased-note.md). + Link within backticks: `[[pure-markdown-examples]]` ```` diff --git a/tests/testdata/input/main-samples/Uppercased-note.md b/tests/testdata/input/main-samples/Uppercased-note.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/testdata/input/main-samples/obsidian-wikilinks.md b/tests/testdata/input/main-samples/obsidian-wikilinks.md index 23d0970..543d9bc 100644 --- a/tests/testdata/input/main-samples/obsidian-wikilinks.md +++ b/tests/testdata/input/main-samples/obsidian-wikilinks.md @@ -6,6 +6,8 @@ Link to [[pure-markdown-examples#Heading 1]]. Link to [[pure-markdown-examples#Heading 1|pure markdown examples]]. +Link to [[uppercased-note]]. + Link within backticks: `[[pure-markdown-examples]]` ```