Merge pull request #16196 from Snuffleupagus/String-replaceAll
Use `String.prototype.replaceAll()` where appropriate
This commit is contained in:
commit
184f5701e9
@ -60,6 +60,7 @@
|
|||||||
"unicorn/prefer-logical-operator-over-ternary": "error",
|
"unicorn/prefer-logical-operator-over-ternary": "error",
|
||||||
"unicorn/prefer-modern-dom-apis": "error",
|
"unicorn/prefer-modern-dom-apis": "error",
|
||||||
"unicorn/prefer-regexp-test": "error",
|
"unicorn/prefer-regexp-test": "error",
|
||||||
|
"unicorn/prefer-string-replace-all": "error",
|
||||||
"unicorn/prefer-string-starts-ends-with": "error",
|
"unicorn/prefer-string-starts-ends-with": "error",
|
||||||
"unicorn/no-typeof-undefined": ["error", { "checkGlobalVariables": false, }],
|
"unicorn/no-typeof-undefined": ["error", { "checkGlobalVariables": false, }],
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
if (!args) {
|
if (!args) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, name) {
|
return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, function (all, name) {
|
||||||
return name in args ? args[name] : "{{" + name + "}}";
|
return name in args ? args[name] : "{{" + name + "}}";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
10
external/builder/builder.js
vendored
10
external/builder/builder.js
vendored
@ -41,7 +41,7 @@ function preprocess(inFilename, outFilename, defines) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function expandCssImports(content, baseUrl) {
|
function expandCssImports(content, baseUrl) {
|
||||||
return content.replace(
|
return content.replaceAll(
|
||||||
/^\s*@import\s+url\(([^)]+)\);\s*$/gm,
|
/^\s*@import\s+url\(([^)]+)\);\s*$/gm,
|
||||||
function (all, url) {
|
function (all, url) {
|
||||||
const file = path.join(path.dirname(baseUrl), url);
|
const file = path.join(path.dirname(baseUrl), url);
|
||||||
@ -121,7 +121,7 @@ function preprocess(inFilename, outFilename, defines) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function expand(line) {
|
function expand(line) {
|
||||||
line = line.replace(/__[\w]+__/g, function (variable) {
|
line = line.replaceAll(/__[\w]+__/g, function (variable) {
|
||||||
variable = variable.substring(2, variable.length - 2);
|
variable = variable.substring(2, variable.length - 2);
|
||||||
if (variable in defines) {
|
if (variable in defines) {
|
||||||
return defines[variable];
|
return defines[variable];
|
||||||
@ -210,9 +210,9 @@ function preprocess(inFilename, outFilename, defines) {
|
|||||||
) {
|
) {
|
||||||
writeLine(
|
writeLine(
|
||||||
line
|
line
|
||||||
.replace(/^\/\/|^<!--/g, " ")
|
.replaceAll(/^\/\/|^<!--/g, " ")
|
||||||
.replace(/(^\s*)\/\*/g, "$1 ")
|
.replaceAll(/(^\s*)\/\*/g, "$1 ")
|
||||||
.replace(/\*\/$|-->$/g, "")
|
.replaceAll(/\*\/$|-->$/g, "")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
external/builder/test-fixtures.js
vendored
4
external/builder/test-fixtures.js
vendored
@ -21,7 +21,7 @@ files.forEach(function (expectationFilename) {
|
|||||||
.readFileSync(expectationFilename)
|
.readFileSync(expectationFilename)
|
||||||
.toString()
|
.toString()
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/__filename/g, fs.realpathSync(inFilename));
|
.replaceAll("__filename", fs.realpathSync(inFilename));
|
||||||
const outLines = [];
|
const outLines = [];
|
||||||
|
|
||||||
const outFilename = function (line) {
|
const outFilename = function (line) {
|
||||||
@ -36,7 +36,7 @@ files.forEach(function (expectationFilename) {
|
|||||||
builder.preprocess(inFilename, outFilename, defines);
|
builder.preprocess(inFilename, outFilename, defines);
|
||||||
out = outLines.join("\n").trim();
|
out = outLines.join("\n").trim();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
out = ("Error: " + e.message).replace(/^/gm, "//");
|
out = ("Error: " + e.message).replaceAll(/^/gm, "//");
|
||||||
}
|
}
|
||||||
if (out !== expectation) {
|
if (out !== expectation) {
|
||||||
errors++;
|
errors++;
|
||||||
|
4
external/builder/test-fixtures_esprima.js
vendored
4
external/builder/test-fixtures_esprima.js
vendored
@ -21,7 +21,7 @@ files.forEach(function (expectationFilename) {
|
|||||||
.readFileSync(expectationFilename)
|
.readFileSync(expectationFilename)
|
||||||
.toString()
|
.toString()
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/__filename/g, fs.realpathSync(inFilename));
|
.replaceAll("__filename", fs.realpathSync(inFilename));
|
||||||
const input = fs.readFileSync(inFilename).toString();
|
const input = fs.readFileSync(inFilename).toString();
|
||||||
|
|
||||||
const defines = {
|
const defines = {
|
||||||
@ -42,7 +42,7 @@ files.forEach(function (expectationFilename) {
|
|||||||
try {
|
try {
|
||||||
out = p2.preprocessPDFJSCode(ctx, input);
|
out = p2.preprocessPDFJSCode(ctx, input);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
out = ("Error: " + e.message).replace(/^/gm, "//");
|
out = ("Error: " + e.message).replaceAll(/^/gm, "//");
|
||||||
}
|
}
|
||||||
if (out !== expectation) {
|
if (out !== expectation) {
|
||||||
errors++;
|
errors++;
|
||||||
|
2
external/cmapscompress/parse.js
vendored
2
external/cmapscompress/parse.js
vendored
@ -19,7 +19,7 @@ exports.parseAdobeCMap = function (content) {
|
|||||||
throw new Error("cmap was not found");
|
throw new Error("cmap was not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = m[1].replace(/\r\n?/g, "\n");
|
const body = m[1].replaceAll(/\r\n?/g, "\n");
|
||||||
const result = {
|
const result = {
|
||||||
type: 1,
|
type: 1,
|
||||||
wmode: 0,
|
wmode: 0,
|
||||||
|
2
external/importL10n/locales.js
vendored
2
external/importL10n/locales.js
vendored
@ -27,7 +27,7 @@ const DEFAULT_LOCALE = "en-US";
|
|||||||
const EXCLUDE_LANG_CODES = ["ca-valencia", "ja-JP-mac"];
|
const EXCLUDE_LANG_CODES = ["ca-valencia", "ja-JP-mac"];
|
||||||
|
|
||||||
function normalizeText(s) {
|
function normalizeText(s) {
|
||||||
return s.replace(/\r\n?/g, "\n").replace(/\uFEFF/g, "");
|
return s.replaceAll(/\r\n?/g, "\n").replaceAll("\uFEFF", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadLanguageCodes() {
|
function downloadLanguageCodes() {
|
||||||
|
11
gulpfile.js
11
gulpfile.js
@ -130,7 +130,7 @@ function safeSpawnSync(command, parameters, options) {
|
|||||||
if (!/[\s`~!#$*(){[|\\;'"<>?]/.test(param)) {
|
if (!/[\s`~!#$*(){[|\\;'"<>?]/.test(param)) {
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
return '"' + param.replace(/([$\\"`])/g, "\\$1") + '"';
|
return '"' + param.replaceAll(/([$\\"`])/g, "\\$1") + '"';
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = spawnSync(command, parameters, options);
|
const result = spawnSync(command, parameters, options);
|
||||||
@ -909,7 +909,7 @@ function preprocessCSS(source, defines) {
|
|||||||
|
|
||||||
// Strip out all license headers in the middle.
|
// Strip out all license headers in the middle.
|
||||||
const reg = /\n\/\* Copyright(.|\n)*?Mozilla Foundation(.|\n)*?\*\//g;
|
const reg = /\n\/\* Copyright(.|\n)*?Mozilla Foundation(.|\n)*?\*\//g;
|
||||||
out = out.replace(reg, "");
|
out = out.replaceAll(reg, "");
|
||||||
|
|
||||||
const i = source.lastIndexOf("/");
|
const i = source.lastIndexOf("/");
|
||||||
return createStringSource(source.substr(i + 1), out);
|
return createStringSource(source.substr(i + 1), out);
|
||||||
@ -1557,9 +1557,10 @@ function buildLibHelper(bundleDefines, inputStream, outputDir) {
|
|||||||
}).code;
|
}).code;
|
||||||
const removeCjsSrc =
|
const removeCjsSrc =
|
||||||
/^(var\s+\w+\s*=\s*(_interopRequireDefault\()?require\(".*?)(?:\/src)(\/[^"]*"\)\)?;)$/gm;
|
/^(var\s+\w+\s*=\s*(_interopRequireDefault\()?require\(".*?)(?:\/src)(\/[^"]*"\)\)?;)$/gm;
|
||||||
content = content.replace(removeCjsSrc, (all, prefix, interop, suffix) => {
|
content = content.replaceAll(
|
||||||
return prefix + suffix;
|
removeCjsSrc,
|
||||||
});
|
(all, prefix, interop, suffix) => prefix + suffix
|
||||||
|
);
|
||||||
return licenseHeaderLibre + content;
|
return licenseHeaderLibre + content;
|
||||||
}
|
}
|
||||||
const babel = require("@babel/core");
|
const babel = require("@babel/core");
|
||||||
|
@ -989,7 +989,7 @@ class Catalog {
|
|||||||
if (javaScript === null) {
|
if (javaScript === null) {
|
||||||
javaScript = new Map();
|
javaScript = new Map();
|
||||||
}
|
}
|
||||||
js = stringToPDFString(js).replace(/\u0000/g, "");
|
js = stringToPDFString(js).replaceAll("\x00", "");
|
||||||
javaScript.set(name, js);
|
javaScript.set(name, js);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ function escapePDFName(str) {
|
|||||||
// Replace "(", ")", "\n", "\r" and "\" by "\(", "\)", "\\n", "\\r" and "\\"
|
// Replace "(", ")", "\n", "\r" and "\" by "\(", "\)", "\\n", "\\r" and "\\"
|
||||||
// in order to write it in a PDF file.
|
// in order to write it in a PDF file.
|
||||||
function escapeString(str) {
|
function escapeString(str) {
|
||||||
return str.replace(/([()\\\n\r])/g, match => {
|
return str.replaceAll(/([()\\\n\r])/g, match => {
|
||||||
if (match === "\n") {
|
if (match === "\n") {
|
||||||
return "\\n";
|
return "\\n";
|
||||||
} else if (match === "\r") {
|
} else if (match === "\r") {
|
||||||
@ -341,7 +341,7 @@ function _collectJS(entry, xref, list, parents) {
|
|||||||
} else if (typeof js === "string") {
|
} else if (typeof js === "string") {
|
||||||
code = js;
|
code = js;
|
||||||
}
|
}
|
||||||
code = code && stringToPDFString(code).replace(/\u0000/g, "");
|
code = code && stringToPDFString(code).replaceAll("\x00", "");
|
||||||
if (code) {
|
if (code) {
|
||||||
list.push(code);
|
list.push(code);
|
||||||
}
|
}
|
||||||
|
@ -1144,7 +1144,7 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
let fontFamily = descriptor.get("FontFamily");
|
let fontFamily = descriptor.get("FontFamily");
|
||||||
// For example, "Wingdings 3" is not a valid font name in the css specs.
|
// For example, "Wingdings 3" is not a valid font name in the css specs.
|
||||||
fontFamily = fontFamily.replace(/[ ]+(\d)/g, "$1");
|
fontFamily = fontFamily.replaceAll(/[ ]+(\d)/g, "$1");
|
||||||
const fontWeight = descriptor.get("FontWeight");
|
const fontWeight = descriptor.get("FontWeight");
|
||||||
|
|
||||||
// Angle is expressed in degrees counterclockwise in PDF
|
// Angle is expressed in degrees counterclockwise in PDF
|
||||||
|
@ -4086,7 +4086,7 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Using base font name as a font name.
|
// Using base font name as a font name.
|
||||||
baseFontName = baseFontName.name.replace(/[,_]/g, "-");
|
baseFontName = baseFontName.name.replaceAll(/[,_]/g, "-");
|
||||||
const metrics = this.getBaseFontMetrics(baseFontName);
|
const metrics = this.getBaseFontMetrics(baseFontName);
|
||||||
|
|
||||||
// Simulating descriptor flags attribute
|
// Simulating descriptor flags attribute
|
||||||
|
@ -68,9 +68,9 @@ class FileSpec {
|
|||||||
if (!this._filename && this.root) {
|
if (!this._filename && this.root) {
|
||||||
const filename = pickPlatformItem(this.root) || "unnamed";
|
const filename = pickPlatformItem(this.root) || "unnamed";
|
||||||
this._filename = stringToPDFString(filename)
|
this._filename = stringToPDFString(filename)
|
||||||
.replace(/\\\\/g, "\\")
|
.replaceAll("\\\\", "\\")
|
||||||
.replace(/\\\//g, "/")
|
.replaceAll("\\/", "/")
|
||||||
.replace(/\\/g, "/");
|
.replaceAll("\\", "/");
|
||||||
}
|
}
|
||||||
return this._filename;
|
return this._filename;
|
||||||
}
|
}
|
||||||
|
@ -903,7 +903,7 @@ function createPostTable(properties) {
|
|||||||
|
|
||||||
function createPostscriptName(name) {
|
function createPostscriptName(name) {
|
||||||
// See https://docs.microsoft.com/en-us/typography/opentype/spec/recom#name.
|
// See https://docs.microsoft.com/en-us/typography/opentype/spec/recom#name.
|
||||||
return name.replace(/[^\x21-\x7E]|[[\](){}<>/%]/g, "").slice(0, 63);
|
return name.replaceAll(/[^\x21-\x7E]|[[\](){}<>/%]/g, "").slice(0, 63);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNameTable(name, proto) {
|
function createNameTable(name, proto) {
|
||||||
@ -994,7 +994,7 @@ class Font {
|
|||||||
// Fallback to checking the font name, in order to improve text-selection,
|
// Fallback to checking the font name, in order to improve text-selection,
|
||||||
// since the /Flags-entry is often wrong (fixes issue13845.pdf).
|
// since the /Flags-entry is often wrong (fixes issue13845.pdf).
|
||||||
if (!isSerifFont && !properties.isSimulatedFlags) {
|
if (!isSerifFont && !properties.isSimulatedFlags) {
|
||||||
const baseName = name.replace(/[,_]/g, "-").split("-")[0],
|
const baseName = name.replaceAll(/[,_]/g, "-").split("-")[0],
|
||||||
serifFonts = getSerifFonts();
|
serifFonts = getSerifFonts();
|
||||||
for (const namePart of baseName.split("+")) {
|
for (const namePart of baseName.split("+")) {
|
||||||
if (serifFonts[namePart]) {
|
if (serifFonts[namePart]) {
|
||||||
@ -1445,7 +1445,7 @@ class Font {
|
|||||||
for (let j = 0, jj = nameTable.length; j < jj; j++) {
|
for (let j = 0, jj = nameTable.length; j < jj; j++) {
|
||||||
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
|
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
|
||||||
const nameEntry =
|
const nameEntry =
|
||||||
nameTable[j][k] && nameTable[j][k].replace(/\s/g, "");
|
nameTable[j][k] && nameTable[j][k].replaceAll(/\s/g, "");
|
||||||
if (!nameEntry) {
|
if (!nameEntry) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizeFontName(name) {
|
function normalizeFontName(name) {
|
||||||
return name.replace(/[,_]/g, "-").replace(/\s/g, "");
|
return name.replaceAll(/[,_]/g, "-").replaceAll(/\s/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -36,12 +36,12 @@ class MetadataParser {
|
|||||||
// Start by removing any "junk" before the first tag (see issue 10395).
|
// Start by removing any "junk" before the first tag (see issue 10395).
|
||||||
return data
|
return data
|
||||||
.replace(/^[^<]+/, "")
|
.replace(/^[^<]+/, "")
|
||||||
.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
|
.replaceAll(/>\\376\\377([^<]+)/g, function (all, codes) {
|
||||||
const bytes = codes
|
const bytes = codes
|
||||||
.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
|
.replaceAll(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
|
||||||
return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
|
return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
|
||||||
})
|
})
|
||||||
.replace(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
|
.replaceAll(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "amp":
|
case "amp":
|
||||||
return "&";
|
return "&";
|
||||||
|
@ -99,7 +99,7 @@ class FontFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pattern = /,|-|_| |bolditalic|bold|italic|regular|it/gi;
|
const pattern = /,|-|_| |bolditalic|bold|italic|regular|it/gi;
|
||||||
let name = fontName.replace(pattern, "");
|
let name = fontName.replaceAll(pattern, "");
|
||||||
font = this.fonts.get(name);
|
font = this.fonts.get(name);
|
||||||
if (font) {
|
if (font) {
|
||||||
this.cache.set(fontName, font);
|
this.cache.set(fontName, font);
|
||||||
@ -109,7 +109,7 @@ class FontFinder {
|
|||||||
|
|
||||||
const maybe = [];
|
const maybe = [];
|
||||||
for (const [family, pdfFont] of this.fonts.entries()) {
|
for (const [family, pdfFont] of this.fonts.entries()) {
|
||||||
if (family.replace(pattern, "").toLowerCase().startsWith(name)) {
|
if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
|
||||||
maybe.push(pdfFont);
|
maybe.push(pdfFont);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ class FontFinder {
|
|||||||
if (
|
if (
|
||||||
pdfFont.regular.name &&
|
pdfFont.regular.name &&
|
||||||
pdfFont.regular.name
|
pdfFont.regular.name
|
||||||
.replace(pattern, "")
|
.replaceAll(pattern, "")
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.startsWith(name)
|
.startsWith(name)
|
||||||
) {
|
) {
|
||||||
@ -129,9 +129,9 @@ class FontFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (maybe.length === 0) {
|
if (maybe.length === 0) {
|
||||||
name = name.replace(/psmt|mt/gi, "");
|
name = name.replaceAll(/psmt|mt/gi, "");
|
||||||
for (const [family, pdfFont] of this.fonts.entries()) {
|
for (const [family, pdfFont] of this.fonts.entries()) {
|
||||||
if (family.replace(pattern, "").toLowerCase().startsWith(name)) {
|
if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
|
||||||
maybe.push(pdfFont);
|
maybe.push(pdfFont);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ class FontFinder {
|
|||||||
if (
|
if (
|
||||||
pdfFont.regular.name &&
|
pdfFont.regular.name &&
|
||||||
pdfFont.regular.name
|
pdfFont.regular.name
|
||||||
.replace(pattern, "")
|
.replaceAll(pattern, "")
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.startsWith(name)
|
.startsWith(name)
|
||||||
) {
|
) {
|
||||||
|
@ -5731,7 +5731,7 @@ class Text extends ContentObject {
|
|||||||
|
|
||||||
[$finalize]() {
|
[$finalize]() {
|
||||||
if (typeof this[$content] === "string") {
|
if (typeof this[$content] === "string") {
|
||||||
this[$content] = this[$content].replace(/\r\n/g, "\n");
|
this[$content] = this[$content].replaceAll("\r\n", "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,9 +231,9 @@ class XhtmlObject extends XmlObject {
|
|||||||
|
|
||||||
[$onText](str, richText = false) {
|
[$onText](str, richText = false) {
|
||||||
if (!richText) {
|
if (!richText) {
|
||||||
str = str.replace(crlfRegExp, "");
|
str = str.replaceAll(crlfRegExp, "");
|
||||||
if (!this.style.includes("xfa-spacerun:yes")) {
|
if (!this.style.includes("xfa-spacerun:yes")) {
|
||||||
str = str.replace(spacesRegExp, " ");
|
str = str.replaceAll(spacesRegExp, " ");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this[$richText] = true;
|
this[$richText] = true;
|
||||||
@ -351,7 +351,7 @@ class XhtmlObject extends XmlObject {
|
|||||||
let value;
|
let value;
|
||||||
if (this[$richText]) {
|
if (this[$richText]) {
|
||||||
value = this[$content]
|
value = this[$content]
|
||||||
? this[$content].replace(crlfForRichTextRegExp, "\n")
|
? this[$content].replaceAll(crlfForRichTextRegExp, "\n")
|
||||||
: undefined;
|
: undefined;
|
||||||
} else {
|
} else {
|
||||||
value = this[$content] || undefined;
|
value = this[$content] || undefined;
|
||||||
|
@ -48,7 +48,7 @@ function isWhitespaceString(s) {
|
|||||||
|
|
||||||
class XMLParserBase {
|
class XMLParserBase {
|
||||||
_resolveEntities(s) {
|
_resolveEntities(s) {
|
||||||
return s.replace(/&([^;]+);/g, (all, entity) => {
|
return s.replaceAll(/&([^;]+);/g, (all, entity) => {
|
||||||
if (entity.substring(0, 2) === "#x") {
|
if (entity.substring(0, 2) === "#x") {
|
||||||
return String.fromCodePoint(parseInt(entity.substring(2), 16));
|
return String.fromCodePoint(parseInt(entity.substring(2), 16));
|
||||||
} else if (entity.substring(0, 1) === "#") {
|
} else if (entity.substring(0, 1) === "#") {
|
||||||
|
@ -152,7 +152,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
|||||||
parts[i] = parts[i].slice(0, quotindex);
|
parts[i] = parts[i].slice(0, quotindex);
|
||||||
parts.length = i + 1; // Truncates and stop the iteration.
|
parts.length = i + 1; // Truncates and stop the iteration.
|
||||||
}
|
}
|
||||||
parts[i] = parts[i].replace(/\\(.)/g, "$1");
|
parts[i] = parts[i].replaceAll(/\\(.)/g, "$1");
|
||||||
}
|
}
|
||||||
value = parts.join('"');
|
value = parts.join('"');
|
||||||
}
|
}
|
||||||
@ -194,13 +194,13 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
|||||||
// encoding = q or b
|
// encoding = q or b
|
||||||
// encoded-text = any printable ASCII character other than ? or space.
|
// encoded-text = any printable ASCII character other than ? or space.
|
||||||
// ... but Firefox permits ? and space.
|
// ... but Firefox permits ? and space.
|
||||||
return value.replace(
|
return value.replaceAll(
|
||||||
/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,
|
/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,
|
||||||
function (matches, charset, encoding, text) {
|
function (matches, charset, encoding, text) {
|
||||||
if (encoding === "q" || encoding === "Q") {
|
if (encoding === "q" || encoding === "Q") {
|
||||||
// RFC 2047 section 4.2.
|
// RFC 2047 section 4.2.
|
||||||
text = text.replace(/_/g, " ");
|
text = text.replaceAll("_", " ");
|
||||||
text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
|
text = text.replaceAll(/=([0-9a-fA-F]{2})/g, function (match, hex) {
|
||||||
return String.fromCharCode(parseInt(hex, 16));
|
return String.fromCharCode(parseInt(hex, 16));
|
||||||
});
|
});
|
||||||
return textdecode(charset, text);
|
return textdecode(charset, text);
|
||||||
|
@ -60,7 +60,7 @@ class AForm {
|
|||||||
if (!actions) {
|
if (!actions) {
|
||||||
actions = [];
|
actions = [];
|
||||||
this._dateActionsCache.set(cFormat, actions);
|
this._dateActionsCache.set(cFormat, actions);
|
||||||
cFormat.replace(
|
cFormat.replaceAll(
|
||||||
/(d+)|(m+)|(y+)|(H+)|(M+)|(s+)/g,
|
/(d+)|(m+)|(y+)|(H+)|(M+)|(s+)/g,
|
||||||
function (match, d, m, y, H, M, s) {
|
function (match, d, m, y, H, M, s) {
|
||||||
if (d) {
|
if (d) {
|
||||||
|
@ -65,7 +65,7 @@ class Util extends PDFObject {
|
|||||||
const ZERO = 4;
|
const ZERO = 4;
|
||||||
const HASH = 8;
|
const HASH = 8;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
return args[0].replace(
|
return args[0].replaceAll(
|
||||||
pattern,
|
pattern,
|
||||||
function (match, nDecSep, cFlags, nWidth, nPrecision, cConvChar) {
|
function (match, nDecSep, cFlags, nWidth, nPrecision, cConvChar) {
|
||||||
// cConvChar must be one of d, f, s, x
|
// cConvChar must be one of d, f, s, x
|
||||||
@ -287,7 +287,7 @@ class Util extends PDFObject {
|
|||||||
|
|
||||||
const patterns =
|
const patterns =
|
||||||
/(mmmm|mmm|mm|m|dddd|ddd|dd|d|yyyy|yy|HH|H|hh|h|MM|M|ss|s|tt|t|\\.)/g;
|
/(mmmm|mmm|mm|m|dddd|ddd|dd|d|yyyy|yy|HH|H|hh|h|MM|M|ss|s|tt|t|\\.)/g;
|
||||||
return cFormat.replace(patterns, function (match, pattern) {
|
return cFormat.replaceAll(patterns, function (match, pattern) {
|
||||||
if (pattern in handlers) {
|
if (pattern in handlers) {
|
||||||
return handlers[pattern](data);
|
return handlers[pattern](data);
|
||||||
}
|
}
|
||||||
@ -523,12 +523,12 @@ class Util extends PDFObject {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// escape the string
|
// escape the string
|
||||||
const escapedFormat = cFormat.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
const escapedFormat = cFormat.replaceAll(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
||||||
const patterns =
|
const patterns =
|
||||||
/(mmmm|mmm|mm|m|dddd|ddd|dd|d|yyyy|yy|HH|H|hh|h|MM|M|ss|s|tt|t)/g;
|
/(mmmm|mmm|mm|m|dddd|ddd|dd|d|yyyy|yy|HH|H|hh|h|MM|M|ss|s|tt|t)/g;
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
const re = escapedFormat.replace(
|
const re = escapedFormat.replaceAll(
|
||||||
patterns,
|
patterns,
|
||||||
function (match, patternElement) {
|
function (match, patternElement) {
|
||||||
const { pattern, action } = handlers[patternElement];
|
const { pattern, action } = handlers[patternElement];
|
||||||
|
@ -157,9 +157,10 @@ describe("ui_utils", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should modify string with non-displayable characters", function () {
|
it("should modify string with non-displayable characters", function () {
|
||||||
const str = Array.from(Array(32).keys())
|
const str = Array.from(
|
||||||
.map(x => String.fromCharCode(x) + "a")
|
Array(32).keys(),
|
||||||
.join("");
|
x => String.fromCharCode(x) + "a"
|
||||||
|
).join("");
|
||||||
// \x00 is replaced by an empty string.
|
// \x00 is replaced by an empty string.
|
||||||
const expected =
|
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";
|
"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";
|
||||||
|
@ -103,8 +103,8 @@ describe("XML", function () {
|
|||||||
const buffer = [];
|
const buffer = [];
|
||||||
root.dump(buffer);
|
root.dump(buffer);
|
||||||
|
|
||||||
expect(buffer.join("").replace(/\s+/g, "")).toEqual(
|
expect(buffer.join("").replaceAll(/\s+/g, "")).toEqual(
|
||||||
xml.replace(/\s+/g, "")
|
xml.replaceAll(/\s+/g, "")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -79,7 +79,7 @@ WebServer.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
_handler(req, res) {
|
_handler(req, res) {
|
||||||
var url = req.url.replace(/\/\//g, "/");
|
var url = req.url.replaceAll("//", "/");
|
||||||
var urlParts = /([^?]*)((?:\?(.*))?)/.exec(url);
|
var urlParts = /([^?]*)((?:\?(.*))?)/.exec(url);
|
||||||
try {
|
try {
|
||||||
// Guard against directory traversal attacks such as
|
// Guard against directory traversal attacks such as
|
||||||
@ -89,7 +89,7 @@ WebServer.prototype = {
|
|||||||
// path.normalize returns a path on the basis of the current platform.
|
// path.normalize returns a path on the basis of the current platform.
|
||||||
// Windows paths cause issues in statFile and serverDirectoryIndex.
|
// Windows paths cause issues in statFile and serverDirectoryIndex.
|
||||||
// Converting to unix path would avoid platform checks in said functions.
|
// Converting to unix path would avoid platform checks in said functions.
|
||||||
pathPart = pathPart.replace(/\\/g, "/");
|
pathPart = pathPart.replaceAll("\\", "/");
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// If the URI cannot be decoded, a `URIError` is thrown. This happens for
|
// If the URI cannot be decoded, a `URIError` is thrown. This happens for
|
||||||
// malformed URIs such as `http://localhost:8888/%s%s` and should be
|
// malformed URIs such as `http://localhost:8888/%s%s` and should be
|
||||||
@ -196,11 +196,11 @@ WebServer.prototype = {
|
|||||||
// Escape untrusted input so that it can safely be used in a HTML response
|
// Escape untrusted input so that it can safely be used in a HTML response
|
||||||
// in HTML and in HTML attributes.
|
// in HTML and in HTML attributes.
|
||||||
return untrusted
|
return untrusted
|
||||||
.replace(/&/g, "&")
|
.replaceAll("&", "&")
|
||||||
.replace(/</g, "<")
|
.replaceAll("<", "<")
|
||||||
.replace(/>/g, ">")
|
.replaceAll(">", ">")
|
||||||
.replace(/"/g, """)
|
.replaceAll('"', """)
|
||||||
.replace(/'/g, "'");
|
.replaceAll("'", "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveDirectoryIndex(dir) {
|
function serveDirectoryIndex(dir) {
|
||||||
|
@ -117,7 +117,7 @@ function formatL10nValue(text, args) {
|
|||||||
if (!args) {
|
if (!args) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
|
return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
|
||||||
return name in args ? args[name] : "{{" + name + "}}";
|
return name in args ? args[name] : "{{" + name + "}}";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -663,7 +663,7 @@ class PDFFindController {
|
|||||||
#convertToRegExpString(query, hasDiacritics) {
|
#convertToRegExpString(query, hasDiacritics) {
|
||||||
const { matchDiacritics } = this._state;
|
const { matchDiacritics } = this._state;
|
||||||
let isUnicode = false;
|
let isUnicode = false;
|
||||||
query = query.replace(
|
query = query.replaceAll(
|
||||||
SPECIAL_CHARS_REG_EXP,
|
SPECIAL_CHARS_REG_EXP,
|
||||||
(
|
(
|
||||||
match,
|
match,
|
||||||
|
@ -352,7 +352,7 @@ class PDFLinkService {
|
|||||||
if (params.has("search")) {
|
if (params.has("search")) {
|
||||||
this.eventBus.dispatch("findfromurlhash", {
|
this.eventBus.dispatch("findfromurlhash", {
|
||||||
source: this,
|
source: this,
|
||||||
query: params.get("search").replace(/"/g, ""),
|
query: params.get("search").replaceAll('"', ""),
|
||||||
phraseSearch: params.get("phrase") === "true",
|
phraseSearch: params.get("phrase") === "true",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,6 @@ function parseQueryString(query) {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NullCharactersRegExp = /\x00/g;
|
|
||||||
const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
|
const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,9 +223,9 @@ function removeNullCharacters(str, replaceInvisible = false) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
if (replaceInvisible) {
|
if (replaceInvisible) {
|
||||||
str = str.replace(InvisibleCharactersRegExp, " ");
|
str = str.replaceAll(InvisibleCharactersRegExp, " ");
|
||||||
}
|
}
|
||||||
return str.replace(NullCharactersRegExp, "");
|
return str.replaceAll("\x00", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user