1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Remove non-displayable chars from outline title (#14267)

- it aims to fix #14267;
 - there is nothing about chars in range [0-1F] in the specs but acrobat doesn't display them in any way.
This commit is contained in:
Calixte Denizet 2021-11-12 19:41:32 +01:00
parent 7d6d3fc124
commit 7041c62ccf
6 changed files with 38 additions and 3 deletions

View file

@ -566,16 +566,20 @@ class AbortException extends BaseException {
}
}
const NullCharactersRegExp = /\x00/g;
const NullCharactersRegExp = /\x00+/g;
const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
/**
* @param {string} str
*/
function removeNullCharacters(str) {
function removeNullCharacters(str, replaceInvisible = false) {
if (typeof str !== "string") {
warn("The argument for removeNullCharacters must be a string.");
return str;
}
if (replaceInvisible) {
str = str.replace(InvisibleCharactersRegExp, " ");
}
return str.replace(NullCharactersRegExp, "");
}