1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 23:58:07 +02:00

PDF names need to be escaped when saving

This commit is contained in:
Calixte Denizet 2020-09-09 18:39:14 +02:00
parent f9d56320f5
commit dc4eb71ff1
4 changed files with 56 additions and 2 deletions

View file

@ -15,6 +15,7 @@
import { Dict, Ref } from "../../src/core/primitives.js";
import {
escapePDFName,
getInheritableProperty,
isWhiteSpace,
log2,
@ -226,4 +227,16 @@ describe("core_utils", function () {
]);
});
});
describe("escapePDFName", function () {
it("should escape PDF name", function () {
expect(escapePDFName("hello")).toEqual("hello");
expect(escapePDFName("\xfehello")).toEqual("#fehello");
expect(escapePDFName("he\xfell\xffo")).toEqual("he#fell#ffo");
expect(escapePDFName("\xfehe\xfell\xffo\xff")).toEqual(
"#fehe#fell#ffo#ff"
);
expect(escapePDFName("#h#e#l#l#o")).toEqual("#23h#23e#23l#23l#23o");
});
});
});

View file

@ -95,5 +95,20 @@ describe("Writer", function () {
expect(buffer.join("")).toEqual(expected);
done();
});
it("should write a Dict in escaping PDF names", function (done) {
const dict = new Dict(null);
dict.set("A", 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>>";
expect(buffer.join("")).toEqual(expected);
done();
});
});
});