fix: normalize path separators for keyword matching on Windows

This commit is contained in:
Abhay 2026-04-19 22:37:29 +05:30
parent 67ca1bc959
commit a2d981aff9
1 changed files with 7 additions and 1 deletions

View File

@ -83,7 +83,10 @@ impl<'a> Stream<'a> {
None => return true,
};
let path = util::to_lowercase(path);
let mut path = util::to_lowercase(path);
if cfg!(windows) {
path = path.replace('\\', "/");
}
let mut path = path.as_str();
match path.rfind(keywords_last) {
Some(idx) => {
@ -202,6 +205,9 @@ mod tests {
#[case(&["foo", "o", "bar"], "/foo/bar", false)]
#[case(&["/foo/", "/bar"], "/foo/bar", false)]
#[case(&["/foo/", "/bar"], "/foo/baz/bar", true)]
// Forward slash matching on Windows-style paths
#[case(&["bar/meow"], r"~\foo\bar\meow", true)]
#[case(&["bar", "meow"], r"~\foo\bar\meow", true)]
fn query(#[case] keywords: &[&str], #[case] path: &str, #[case] is_match: bool) {
let db = &mut Database::new(PathBuf::new(), Vec::new(), |_| Vec::new(), false);
let options = StreamOptions::new(0).with_keywords(keywords.iter());