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:
parent
f9d56320f5
commit
dc4eb71ff1
4 changed files with 56 additions and 2 deletions
|
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue