Skip to content

Commit

Permalink
Merge pull request #12364 from calixteman/really_fix_name_issue
Browse files Browse the repository at this point in the history
Dict keys need to be escaped too when saving
  • Loading branch information
brendandahl authored Sep 11, 2020
2 parents aef3fed + fc15459 commit 008eed0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(">>");
Expand Down
4 changes: 2 additions & 2 deletions test/unit/writer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 008eed0

Please sign in to comment.