mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-03 13:45:49 +02:00
Fix escapePDFName producing malformed name escapes for control characters
escapePDFName emitted a single hex digit for character codes below 0x10 (TAB became #9, not #09). PDF 32000-1 7.3.5 requires exactly two hex digits after #. On re-save (annotations, form fields, font names) such a Name is written malformed and the lexer mis-parses it on reload, dropping bytes. Pad the hex to two digits; a no-op for codes 0x10 to 0xFF.
This commit is contained in:
parent
614349086b
commit
9710372a1b
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user