Skip to content

Commit 4bd31cd

Browse files
committed
Merge pull request #122 from caisui/fix/fuzzy
fix fuzzyMatcher:some issues
2 parents 365717f + 012eaf6 commit 4bd31cd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

common/content/hints.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,13 +846,18 @@ const Hints = Module("hints", {
846846
* found in the link.
847847
*/
848848
function fuzzyMatcher(hintString) {
849-
expression = '';
849+
var expression = '';
850850

851851
// Build a regex for fuzzy matching with the input.
852852
//
853853
// If the input is 'abc', the regex will be '[^a]*a[^b]*b[^c]c'.
854-
for (var i = 0; i < hintString.length; i ++) {
854+
var escapeChar = new Set("()[{?.*+^$|\\");
855+
for (var i = 0, j = hintString.length; i < j; i ++) {
855856
var char = hintString[i];
857+
858+
if (escapeChar.has(char))
859+
char = "\\" + char;
860+
856861
expression += '[^' + char + ']*' + char;
857862
}
858863

0 commit comments

Comments
 (0)