Skip to content

Commit c8ed291

Browse files
Merge pull request #19836 from Snuffleupagus/issue-19835
Always fallback to checking all destinations, when lookup fails (issue 19835)
2 parents c63c51e + adc9eb5 commit c8ed291

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

src/core/catalog.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ class Catalog {
682682
const dest = fetchDest(value);
683683
if (dest) {
684684
// Always let the NameTree take precedence.
685-
dests[key] ||= dest;
685+
dests[stringToPDFString(key)] ||= dest;
686686
}
687687
}
688688
}
@@ -701,12 +701,12 @@ class Catalog {
701701
}
702702
}
703703

704-
if (rawDests[0] instanceof NameTree) {
705-
// Fallback to checking the *entire* NameTree, in an attempt to handle
706-
// corrupt PDF documents with out-of-order NameTrees (fixes issue 10272).
704+
// Always fallback to checking all destinations, in order to support:
705+
// - PDF documents with out-of-order NameTrees (fixes issue 10272).
706+
// - Destination keys that use PDFDocEncoding (fixes issue 19835).
707+
if (rawDests.length) {
707708
const dest = this.destinations[id];
708709
if (dest) {
709-
warn(`Found "${id}" at an incorrect position in the NameTree.`);
710710
return dest;
711711
}
712712
}

test/pdfs/issue19835.pdf.link

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/user-attachments/files/19825124/AAPL-2024-09-28-10-K-d71aeb7ff955e2fc4770624610676221.pdf

test/test_manifest.json

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
"link": true,
2424
"type": "other"
2525
},
26+
{
27+
"id": "issue19835",
28+
"file": "pdfs/issue19835.pdf",
29+
"md5": "2940a2f8a41fae299b9a599b8364d05c",
30+
"rounds": 1,
31+
"link": true,
32+
"type": "other"
33+
},
2634
{
2735
"id": "filled-background-range",
2836
"file": "pdfs/filled-background.pdf",

test/unit/api_spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,28 @@ describe("api", function () {
13991399
await loadingTask.destroy();
14001400
});
14011401

1402+
it("gets a destination, from /Dests dictionary with keys using PDFDocEncoding", async function () {
1403+
if (isNodeJS) {
1404+
pending("Linked test-cases are not supported in Node.js.");
1405+
}
1406+
const loadingTask = getDocument(buildGetDocumentParams("issue19835.pdf"));
1407+
const pdfDoc = await loadingTask.promise;
1408+
1409+
const page3 = await pdfDoc.getPage(3);
1410+
const annots = await page3.getAnnotations();
1411+
1412+
const annot = annots.find(x => x.id === "22R");
1413+
// Sanity check to make sure that we found the "correct" annotation.
1414+
expect(annot.dest).toEqual(
1415+
"\u00f2\u00ab\u00d9\u0025\u006f\u2030\u0062\u2122\u0030\u00ab\u00f4\u0047\u0016\u0142\u00e8\u00bd\u2014\u0063\u00a1\u00db"
1416+
);
1417+
1418+
const dest = await pdfDoc.getDestination(annot.dest);
1419+
expect(dest).toEqual([2, { name: "XYZ" }, 34.0799999, 315.439999, 0]);
1420+
1421+
await loadingTask.destroy();
1422+
});
1423+
14021424
it("gets non-string destination", async function () {
14031425
let numberPromise = pdfDocument.getDestination(4.3);
14041426
let booleanPromise = pdfDocument.getDestination(true);

0 commit comments

Comments
 (0)