fix Unicode substring match requiring exact match

This commit is contained in:
Pascal Kuthe 2023-12-22 20:01:18 +01:00
parent 4a04baf6ba
commit c7893db4b4
No known key found for this signature in database
GPG Key ID: D715E8655AE166A6
3 changed files with 26 additions and 15 deletions

View File

@ -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**

View File

@ -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())

View File

@ -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,