Dict keys need to be escaped too when saving
This commit is contained in:
parent
aef3fedc29
commit
fc154590e8
@ -23,7 +23,7 @@ import { calculateMD5 } from "./crypto.js";
|
|||||||
function writeDict(dict, buffer, transform) {
|
function writeDict(dict, buffer, transform) {
|
||||||
buffer.push("<<");
|
buffer.push("<<");
|
||||||
for (const key of dict.getKeys()) {
|
for (const key of dict.getKeys()) {
|
||||||
buffer.push(` /${key} `);
|
buffer.push(` /${escapePDFName(key)} `);
|
||||||
writeValue(dict.getRaw(key), buffer, transform);
|
writeValue(dict.getRaw(key), buffer, transform);
|
||||||
}
|
}
|
||||||
buffer.push(">>");
|
buffer.push(">>");
|
||||||
|
@ -98,14 +98,14 @@ describe("Writer", function () {
|
|||||||
|
|
||||||
it("should write a Dict in escaping PDF names", function (done) {
|
it("should write a Dict in escaping PDF names", function (done) {
|
||||||
const dict = new Dict(null);
|
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("B", Name.get("#hello"));
|
||||||
dict.set("C", Name.get("he\xfello\xff"));
|
dict.set("C", Name.get("he\xfello\xff"));
|
||||||
|
|
||||||
const buffer = [];
|
const buffer = [];
|
||||||
writeDict(dict, buffer, null);
|
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);
|
expect(buffer.join("")).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user