mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Use String.prototype.replaceAll()
where appropriate
This fairly new method allows replacing *multiple* occurrences within a string without having to use regular expressions. Please refer to: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#browser_compatibility
This commit is contained in:
parent
076bb30b6c
commit
5f64621d46
10 changed files with 15 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue