diff --git a/src/db/stream.rs b/src/db/stream.rs index 24c84e0..87cde06 100644 --- a/src/db/stream.rs +++ b/src/db/stream.rs @@ -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) => { @@ -208,4 +211,16 @@ mod tests { let stream = Stream::new(db, options); assert_eq!(is_match, stream.filter_by_keywords(path)); } + + // Forward slash matching on Windows-style paths + #[cfg(windows)] + #[rstest] + #[case(&["bar/meow"], r"~\foo\bar\meow", true)] + #[case(&["bar", "meow"], r"~\foo\bar\meow", true)] + fn query_windows(#[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()); + let stream = Stream::new(db, options); + assert_eq!(is_match, stream.filter_by_keywords(path)); + } }