From fc154590e8d6d307fc899202c88ae6a8142845ba Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 11 Sep 2020 12:25:05 +0200 Subject: [PATCH] Dict keys need to be escaped too when saving --- src/core/writer.js | 2 +- test/unit/writer_spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/writer.js b/src/core/writer.js index 630357fd0..3499bd961 100644 --- a/src/core/writer.js +++ b/src/core/writer.js @@ -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(">>"); diff --git a/test/unit/writer_spec.js b/test/unit/writer_spec.js index 6f4d47f45..ce89be814 100644 --- a/test/unit/writer_spec.js +++ b/test/unit/writer_spec.js @@ -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();