Skip to content

Commit

Permalink
Replace an ASCII space check with a is_whitespace check in Atom::new
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrutar committed Dec 9, 2024
1 parent 387b17c commit 1a9e169
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions matcher/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -196,7 +196,9 @@ impl Atom {
}
Normalization::Never => (),
}
needle_.push(c);
if !saw_backslash {
needle_.push(c);
}
}
} else {
let chars = chars::graphemes(needle).map(|mut c| {
Expand Down
5 changes: 5 additions & 0 deletions matcher/src/pattern/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1a9e169

Please sign in to comment.