fix(bitap): respect minMatchCharLength in exact-match shortcut#832
Closed
JSap0914 wants to merge 2 commits into
Closed
fix(bitap): respect minMatchCharLength in exact-match shortcut#832JSap0914 wants to merge 2 commits into
JSap0914 wants to merge 2 commits into
Conversation
The fast-path for pattern === text in BitapSearch.searchIn() returned isMatch: true unconditionally, bypassing the minMatchCharLength guard that the non-exact bitap path enforces via convertMaskToIndices. Add a length check that mirrors the bitap path behaviour: when the entire matched region (= text.length for an exact match) is shorter than minMatchCharLength, return isMatch: false with score 1. Closes krisk#831
Owner
|
Nice catch, and the diagnosis on #831 is right. I can't merge it as-is though. The tests import from I've landed the same guard on main in dbb98b6 with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The fast-path in
BitapSearch.searchIn()forpattern === text(exact string equality) returnedisMatch: truewithout checkingminMatchCharLength. The non-exact bitap path enforces this option viaconvertMaskToIndices, but the shortcut bypassed it entirely.Reproduction:
Closes #831
Fix
Added a length guard in the exact-match branch of
BitapSearch.searchIn():This mirrors what
convertMaskToIndicesdoes in the non-exact path.Verification