1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00

Support destinations in NameTrees with encoded keys (issue 14847)

Initially I considered updating the `NameOrNumberTree`-implementation to handle encoded keys, however that quickly became somewhat messy (especially in the `NameOrNumberTree.get`-method) since only NameTrees using string-keys.
Hence the easiest solution, as far as I'm concerned, was thus to just update the `Catalog.destinations`-getter instead. Please note that in the referenced PDF document the `Catalog.destination`-method will thus fallback to fetch all destinations, which should be fine since this is the very first case of encoded keys that we've seen.

Also changes the `NameOrNumberTree.getAll`-method to prevent a possible run-time error, although we've so far not seen such a case, for any non-Array Kids-entries found in a NameTree/NumberTree.

Finally, to improve overall consistency and to hopefully prevent future bugs, the patch also updates a couple of other `NameTree` call-sites to correctly handle encoded keys. (Note that the `Catalog.attachments`-getter was already doing this.)
This commit is contained in:
Jonas Jenwald 2022-04-27 10:34:31 +02:00
parent 981cd5bbfc
commit 71370d012b
5 changed files with 24 additions and 6 deletions

View file

@ -53,6 +53,7 @@
!issue7544.pdf
!issue7507.pdf
!issue6931_reduced.pdf
!issue14847.pdf
!doc_actions.pdf
!issue7580.pdf
!issue7598.pdf

BIN
test/pdfs/issue14847.pdf Normal file

Binary file not shown.

View file

@ -1004,6 +1004,21 @@ describe("api", function () {
await loadingTask.destroy();
});
it("gets a destination, from /Names (NameTree) dictionary with keys using PDFDocEncoding (issue 14847)", async function () {
const loadingTask = getDocument(buildGetDocumentParams("issue14847.pdf"));
const pdfDoc = await loadingTask.promise;
const destination = await pdfDoc.getDestination("index");
expect(destination).toEqual([
{ num: 10, gen: 0 },
{ name: "XYZ" },
85.039,
728.504,
null,
]);
await loadingTask.destroy();
});
it("gets non-string destination", async function () {
let numberPromise = pdfDocument.getDestination(4.3);
let booleanPromise = pdfDocument.getDestination(true);