Merge pull request #21522 from spokodev/w32/pdfjs-escapepdfname

Fix escapePDFName producing malformed name escapes for control characters
This commit is contained in:
calixteman 2026-07-02 18:11:21 +02:00 committed by GitHub
commit d5dafc3fb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -376,7 +376,7 @@ function escapePDFName(str) {
if (start < i) {
buffer.push(str.substring(start, i));
}
buffer.push(`#${char.toString(16)}`);
buffer.push(`#${char.toString(16).padStart(2, "0")}`);
start = i + 1;
}
}

View File

@ -290,6 +290,11 @@ describe("core_utils", function () {
"#23#28#29#3c#3e#5b#5d#7b#7d#2f#25"
);
});
it("should escape control characters using two hexadecimal digits", function () {
expect(escapePDFName("\x00\x09\x0a\x1f")).toEqual("#00#09#0a#1f");
expect(escapePDFName("a\tb")).toEqual("a#09b");
});
});
describe("escapeString", function () {