Skip to content

Commit

Permalink
fix Unicode substring match requiring exact match
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Dec 22, 2023
1 parent 4a04baf commit c7893db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

# [0.3.1] - 2023-12-22

## Bugfixes

* fix Unicode substring matcher expecting an exact match (rejecting trailing characters)

# [0.3.0] - 2023-12-22

## **Breaking Changes**
Expand Down
2 changes: 1 addition & 1 deletion matcher/src/exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl Matcher {
prev_class = char_class;
let score = bonus * BONUS_FIRST_CHAR_MULTIPLIER + SCORE_MATCH;
if score > max_score
&& haystack[i + 1..]
&& haystack[start + i + 1..start + i + needle.len()]
.iter()
.map(|c| c.normalize(&self.config))
.eq(needle[1..].iter().copied())
Expand Down
33 changes: 19 additions & 14 deletions matcher/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,26 +470,31 @@ fn test_normalize() {

#[test]
fn test_unicode() {
assert_matches(
&[FuzzyGreedy, FuzzyOptimal, Substring],
true,
false,
false,
false,
&[(
"你好世界",
"你好",
&[0, 1],
BONUS_BOUNDARY_WHITE * (BONUS_FIRST_CHAR_MULTIPLIER + 1),
)],
);
assert_matches(
&[FuzzyGreedy, FuzzyOptimal],
true,
false,
false,
false,
&[
(
"你好世界",
"你好",
&[0, 1],
BONUS_BOUNDARY_WHITE * (BONUS_FIRST_CHAR_MULTIPLIER + 1),
),
(
"你好世界",
"你世",
&[0, 2],
BONUS_BOUNDARY_WHITE * BONUS_FIRST_CHAR_MULTIPLIER - PENALTY_GAP_START,
),
],
&[(
"你好世界",
"你世",
&[0, 2],
BONUS_BOUNDARY_WHITE * BONUS_FIRST_CHAR_MULTIPLIER - PENALTY_GAP_START,
)],
);
assert_not_matches(
false,
Expand Down

0 comments on commit c7893db

Please sign in to comment.