Skip to content

Commit cc0dada

Browse files
Merge pull request #20524 from calixteman/simplify_regex_escaping
Simplify regex escaping
2 parents 9f4db38 + 01531da commit cc0dada

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

web/pdf_find_controller.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const DIACRITICS_EXCEPTION = new Set([
7777
let DIACRITICS_EXCEPTION_STR; // Lazily initialized, see below.
7878

7979
const DIACRITICS_REG_EXP = /\p{M}+/gu;
80-
const SPECIAL_PUNCTUATION_CHARACTERS = /[.?*{}()[\]\\]/g;
8180
const SPECIAL_CHARS_REG_EXP = /([+^$|])|(\p{P}+)|(\s+)|(\p{M})|(\p{L})/gu;
8281
const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
8382
const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
@@ -735,14 +734,11 @@ class PDFFindController {
735734

736735
if (p1) {
737736
// Escape characters like *+?... to not interfere with regexp syntax.
738-
return addExtraWhitespaces(p1, `\\${p1}`);
737+
return addExtraWhitespaces(p1, RegExp.escape(p1));
739738
}
740739
if (p2) {
741740
// Allow whitespaces around group of punctuation signs.
742-
return addExtraWhitespaces(
743-
p2,
744-
p2.replaceAll(SPECIAL_PUNCTUATION_CHARACTERS, "\\$&")
745-
);
741+
return addExtraWhitespaces(p2, RegExp.escape(p2));
746742
}
747743
if (p3) {
748744
// Replace spaces by \s+ to be sure to match any spaces.

0 commit comments

Comments
 (0)