diff --git a/external/builder/test-fixtures.js b/external/builder/test-fixtures.js index 90b501879..65ea532dc 100644 --- a/external/builder/test-fixtures.js +++ b/external/builder/test-fixtures.js @@ -21,7 +21,7 @@ files.forEach(function (expectationFilename) { .readFileSync(expectationFilename) .toString() .trim() - .replace(/__filename/g, fs.realpathSync(inFilename)); + .replaceAll("__filename", fs.realpathSync(inFilename)); const outLines = []; const outFilename = function (line) { diff --git a/external/builder/test-fixtures_esprima.js b/external/builder/test-fixtures_esprima.js index 35128aee5..947b4cf6c 100644 --- a/external/builder/test-fixtures_esprima.js +++ b/external/builder/test-fixtures_esprima.js @@ -21,7 +21,7 @@ files.forEach(function (expectationFilename) { .readFileSync(expectationFilename) .toString() .trim() - .replace(/__filename/g, fs.realpathSync(inFilename)); + .replaceAll("__filename", fs.realpathSync(inFilename)); const input = fs.readFileSync(inFilename).toString(); const defines = { diff --git a/external/importL10n/locales.js b/external/importL10n/locales.js index bc10a284e..798fd715b 100644 --- a/external/importL10n/locales.js +++ b/external/importL10n/locales.js @@ -27,7 +27,7 @@ const DEFAULT_LOCALE = "en-US"; const EXCLUDE_LANG_CODES = ["ca-valencia", "ja-JP-mac"]; function normalizeText(s) { - return s.replace(/\r\n?/g, "\n").replace(/\uFEFF/g, ""); + return s.replace(/\r\n?/g, "\n").replaceAll("\uFEFF", ""); } function downloadLanguageCodes() { diff --git a/src/core/catalog.js b/src/core/catalog.js index 2dff6d2d0..6cb33baa3 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -989,7 +989,7 @@ class Catalog { if (javaScript === null) { javaScript = new Map(); } - js = stringToPDFString(js).replace(/\u0000/g, ""); + js = stringToPDFString(js).replaceAll("\x00", ""); javaScript.set(name, js); } diff --git a/src/core/core_utils.js b/src/core/core_utils.js index f4541dabe..e721dd980 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -341,7 +341,7 @@ function _collectJS(entry, xref, list, parents) { } else if (typeof js === "string") { code = js; } - code = code && stringToPDFString(code).replace(/\u0000/g, ""); + code = code && stringToPDFString(code).replaceAll("\x00", ""); if (code) { list.push(code); } diff --git a/src/core/file_spec.js b/src/core/file_spec.js index 3eb1c5a7d..da85e9046 100644 --- a/src/core/file_spec.js +++ b/src/core/file_spec.js @@ -68,9 +68,9 @@ class FileSpec { if (!this._filename && this.root) { const filename = pickPlatformItem(this.root) || "unnamed"; this._filename = stringToPDFString(filename) - .replace(/\\\\/g, "\\") - .replace(/\\\//g, "/") - .replace(/\\/g, "/"); + .replaceAll("\\\\", "\\") + .replaceAll("\\/", "/") + .replaceAll("\\", "/"); } return this._filename; } diff --git a/src/display/content_disposition.js b/src/display/content_disposition.js index 0e9ddd11b..787d848d1 100644 --- a/src/display/content_disposition.js +++ b/src/display/content_disposition.js @@ -199,7 +199,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) { function (matches, charset, encoding, text) { if (encoding === "q" || encoding === "Q") { // RFC 2047 section 4.2. - text = text.replace(/_/g, " "); + text = text.replaceAll("_", " "); text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) { return String.fromCharCode(parseInt(hex, 16)); }); diff --git a/test/unit/ui_utils_spec.js b/test/unit/ui_utils_spec.js index 704008175..4935489f7 100644 --- a/test/unit/ui_utils_spec.js +++ b/test/unit/ui_utils_spec.js @@ -157,9 +157,10 @@ describe("ui_utils", function () { }); it("should modify string with non-displayable characters", function () { - const str = Array.from(Array(32).keys()) - .map(x => String.fromCharCode(x) + "a") - .join(""); + const str = Array.from( + Array(32).keys(), + x => String.fromCharCode(x) + "a" + ).join(""); // \x00 is replaced by an empty string. const expected = "a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a"; diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index de8172e6b..249dce587 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -352,7 +352,7 @@ class PDFLinkService { if (params.has("search")) { this.eventBus.dispatch("findfromurlhash", { source: this, - query: params.get("search").replace(/"/g, ""), + query: params.get("search").replaceAll('"', ""), phraseSearch: params.get("phrase") === "true", }); } diff --git a/web/ui_utils.js b/web/ui_utils.js index 82c57c790..59574db85 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -211,7 +211,6 @@ function parseQueryString(query) { return params; } -const NullCharactersRegExp = /\x00/g; const InvisibleCharactersRegExp = /[\x01-\x1F]/g; /** @@ -226,7 +225,7 @@ function removeNullCharacters(str, replaceInvisible = false) { if (replaceInvisible) { str = str.replace(InvisibleCharactersRegExp, " "); } - return str.replace(NullCharactersRegExp, ""); + return str.replaceAll("\x00", ""); } /**