From cbefb334fdaac75d0aaaf09d7c81674668bca31b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 16 Jun 2026 13:40:07 +0200 Subject: [PATCH] Check every LinkAnnotation when testing if inferred links overlap (issue 21458) Currently we only check LinkAnnotations with URLs, but completely ignore e.g. internal destinations, named actions, attachments, SetOCGState actions, JS actions, and ResetForm actions when testing if inferred links overlap any existing annotation. This seems conceptually wrong, since it may easily break intended functionality by overlaying the *correct* DOM element with an inferred link (as was the case in issue 21458). --- test/integration/autolinker_spec.mjs | 37 ++++++++++++++++++++++++++++ test/pdfs/issue21458.pdf.link | 1 + test/test_manifest.json | 8 ++++++ web/annotation_layer_builder.js | 5 +--- 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 test/pdfs/issue21458.pdf.link diff --git a/test/integration/autolinker_spec.mjs b/test/integration/autolinker_spec.mjs index 503f9aed8..596e57604 100644 --- a/test/integration/autolinker_spec.mjs +++ b/test/integration/autolinker_spec.mjs @@ -169,6 +169,43 @@ describe("autolinker", function () { }); }); + describe("issue21458.pdf", function () { + let pages; + + beforeEach(async () => { + pages = await loadAndWait( + "issue21458.pdf", + ".page[data-page-number='1'] .annotationLayer", + null, + null, + { enableAutoLinking: true } + ); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must not add links that overlap internal destinations", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await waitForLinkAnnotations(page); + const linkIds = await page.$$eval( + ".page[data-page-number='1'] .annotationLayer > .linkAnnotation > a", + annotations => + annotations.map(a => a.getAttribute("data-element-id")) + ); + expect(linkIds.length).withContext(`In ${browserName}`).toEqual(42); + linkIds.forEach(id => + expect(id) + .withContext(`In ${browserName}`) + .not.toContain("inferred_link_") + ); + }) + ); + }); + }); + describe("PR 19470", function () { let pages; diff --git a/test/pdfs/issue21458.pdf.link b/test/pdfs/issue21458.pdf.link new file mode 100644 index 000000000..8af2c7e69 --- /dev/null +++ b/test/pdfs/issue21458.pdf.link @@ -0,0 +1 @@ +https://github.com/user-attachments/files/28985267/Gumbel.Distillation.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 856bec321..faa58c969 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -31,6 +31,14 @@ "link": true, "type": "other" }, + { + "id": "issue21458", + "file": "pdfs/issue21458.pdf", + "md5": "875754beca276ab63568e06fd49e8375", + "rounds": 1, + "link": true, + "type": "other" + }, { "id": "filled-background-range", "file": "pdfs/filled-background.pdf", diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 4139210fa..1d9c59133 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -332,10 +332,7 @@ class AnnotationLayerBuilder { let linkAreaRects; for (const annotation of this.#annotations) { - if ( - annotation.annotationType !== AnnotationType.LINK || - !annotation.url - ) { + if (annotation.annotationType !== AnnotationType.LINK) { continue; } // TODO: Add a test case to verify that we can find the intersection