Merge pull request #12364 from calixteman/really_fix_name_issue

Dict keys need to be escaped too when saving
This commit is contained in:
Brendan Dahl 2020-09-11 09:55:12 -07:00 committed by GitHub
commit 008eed0efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ import { calculateMD5 } from "./crypto.js";
function writeDict(dict, buffer, transform) {
buffer.push("<<");
for (const key of dict.getKeys()) {
buffer.push(` /${key} `);
buffer.push(` /${escapePDFName(key)} `);
writeValue(dict.getRaw(key), buffer, transform);
}
buffer.push(">>");

View File

@ -98,14 +98,14 @@ describe("Writer", function () {
it("should write a Dict in escaping PDF names", function (done) {
const dict = new Dict(null);
dict.set("A", Name.get("hello"));
dict.set("\xfeA#", Name.get("hello"));
dict.set("B", Name.get("#hello"));
dict.set("C", Name.get("he\xfello\xff"));
const buffer = [];
writeDict(dict, buffer, null);
const expected = "<< /A /hello /B /#23hello /C /he#fello#ff>>";
const expected = "<< /#feA#23 /hello /B /#23hello /C /he#fello#ff>>";
expect(buffer.join("")).toEqual(expected);
done();