Skip to content

Commit

Permalink
Merge pull request #19449 from Snuffleupagus/autolinking-URL-fuzzy-match
Browse files Browse the repository at this point in the history
Ignore the URLs when checking if inferred links overlap existing LinkAnnotations (PR 19110 follow-up)
  • Loading branch information
Snuffleupagus authored Feb 9, 2025
2 parents d880355 + 37ef0b4 commit 86ae2ca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
33 changes: 33 additions & 0 deletions test/integration/autolinker_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,37 @@ describe("autolinker", function () {
);
});
});

describe("pr19449.pdf", function () {
let pages;

beforeAll(async () => {
pages = await loadAndWait("pr19449.pdf", ".annotationLayer", null, null, {
docBaseUrl: "http://example.com",
enableAutoLinking: true,
});
});

afterAll(async () => {
await closePages(pages);
});

it("must not add links that overlap even if the URLs are different", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const linkIds = await page.$$eval(
".annotationLayer > .linkAnnotation > a",
annotations =>
annotations.map(a => a.getAttribute("data-element-id"))
);
expect(linkIds.length).withContext(`In ${browserName}`).toEqual(1);
linkIds.forEach(id =>
expect(id)
.withContext(`In ${browserName}`)
.not.toContain("inferred_link_")
);
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
!pr6531_1.pdf
!pr6531_2.pdf
!pr7352.pdf
!pr19449.pdf
!bug900822.pdf
!bug1392647.pdf
!issue918.pdf
Expand Down
Binary file added test/pdfs/pr19449.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class AnnotationLayerBuilder {
for (const annotation of this.#annotations) {
if (
annotation.annotationType !== AnnotationType.LINK ||
annotation.url !== link.url
!annotation.url
) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ const PDFViewerApplication = {
// Set some specific preferences for tests.
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
Object.assign(opts, {
docBaseUrl: x => x,
enableAltText: x => x === "true",
enableAutoLinking: x => x === "true",
enableFakeMLManager: x => x === "true",
Expand Down

0 comments on commit 86ae2ca

Please sign in to comment.