diff --git a/matcher/src/pattern.rs b/matcher/src/pattern.rs index 0c554ba..bfc4822 100644 --- a/matcher/src/pattern.rs +++ b/matcher/src/pattern.rs @@ -171,8 +171,8 @@ impl Atom { let mut saw_backslash = false; for mut c in chars::graphemes(needle) { if saw_backslash { - if c == ' ' { - needle_.push(' '); + if c.is_whitespace() { + needle_.push(c); saw_backslash = false; continue; } else { @@ -180,23 +180,25 @@ impl Atom { } } saw_backslash = c == '\\'; - match case { - #[cfg(feature = "unicode-casefold")] - CaseMatching::Ignore => c = chars::to_lower_case(c), - #[cfg(feature = "unicode-casefold")] - CaseMatching::Smart => { - ignore_case = ignore_case && !chars::is_upper_case(c) + if !saw_backslash { + match case { + #[cfg(feature = "unicode-casefold")] + CaseMatching::Ignore => c = chars::to_lower_case(c), + #[cfg(feature = "unicode-casefold")] + CaseMatching::Smart => { + ignore_case = ignore_case && !chars::is_upper_case(c) + } + CaseMatching::Respect => (), } - CaseMatching::Respect => (), - } - match normalization { - #[cfg(feature = "unicode-normalization")] - Normalization::Smart => { - normalize = normalize && chars::normalize(c) == c; + match normalization { + #[cfg(feature = "unicode-normalization")] + Normalization::Smart => { + normalize = normalize && chars::normalize(c) == c; + } + Normalization::Never => (), } - Normalization::Never => (), + needle_.push(c); } - needle_.push(c); } } else { let chars = chars::graphemes(needle).map(|mut c| { diff --git a/matcher/src/pattern/tests.rs b/matcher/src/pattern/tests.rs index 88880ba..c0575f2 100644 --- a/matcher/src/pattern/tests.rs +++ b/matcher/src/pattern/tests.rs @@ -87,6 +87,11 @@ fn case_matching() { fn escape() { let pat = Atom::parse("foo\\ bar", CaseMatching::Smart, Normalization::Smart); assert_eq!(pat.needle.to_string(), "foo bar"); + let pat = Atom::parse("foö\\ bar", CaseMatching::Smart, Normalization::Smart); + assert_eq!(pat.needle.to_string(), "foö bar"); + // escaped double-width IDEOGRAPHIC SPACE + let pat = Atom::parse("foo\\ bar", CaseMatching::Smart, Normalization::Smart); + assert_eq!(pat.needle.to_string(), "foo bar"); let pat = Atom::parse("\\!foo", CaseMatching::Smart, Normalization::Smart); assert_eq!(pat.needle.to_string(), "!foo"); assert_eq!(pat.kind, AtomKind::Fuzzy);