mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-25 00:17:21 +02:00
Merge pull request #20524 from calixteman/simplify_regex_escaping
Simplify regex escaping
This commit is contained in:
commit
cc0dadaabc
@ -77,7 +77,6 @@ const DIACRITICS_EXCEPTION = new Set([
|
|||||||
let DIACRITICS_EXCEPTION_STR; // Lazily initialized, see below.
|
let DIACRITICS_EXCEPTION_STR; // Lazily initialized, see below.
|
||||||
|
|
||||||
const DIACRITICS_REG_EXP = /\p{M}+/gu;
|
const DIACRITICS_REG_EXP = /\p{M}+/gu;
|
||||||
const SPECIAL_PUNCTUATION_CHARACTERS = /[.?*{}()[\]\\]/g;
|
|
||||||
const SPECIAL_CHARS_REG_EXP = /([+^$|])|(\p{P}+)|(\s+)|(\p{M})|(\p{L})/gu;
|
const SPECIAL_CHARS_REG_EXP = /([+^$|])|(\p{P}+)|(\s+)|(\p{M})|(\p{L})/gu;
|
||||||
const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
|
const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
|
||||||
const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
|
const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
|
||||||
@ -735,14 +734,11 @@ class PDFFindController {
|
|||||||
|
|
||||||
if (p1) {
|
if (p1) {
|
||||||
// Escape characters like *+?... to not interfere with regexp syntax.
|
// Escape characters like *+?... to not interfere with regexp syntax.
|
||||||
return addExtraWhitespaces(p1, `\\${p1}`);
|
return addExtraWhitespaces(p1, RegExp.escape(p1));
|
||||||
}
|
}
|
||||||
if (p2) {
|
if (p2) {
|
||||||
// Allow whitespaces around group of punctuation signs.
|
// Allow whitespaces around group of punctuation signs.
|
||||||
return addExtraWhitespaces(
|
return addExtraWhitespaces(p2, RegExp.escape(p2));
|
||||||
p2,
|
|
||||||
p2.replaceAll(SPECIAL_PUNCTUATION_CHARACTERS, "\\$&")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (p3) {
|
if (p3) {
|
||||||
// Replace spaces by \s+ to be sure to match any spaces.
|
// Replace spaces by \s+ to be sure to match any spaces.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user