[Annotation] Strip out the array index in the path only when the path is from a terminal node (bug 1847733)

This commit is contained in:
Calixte Denizet 2023-08-08 15:05:27 +02:00
parent 19c712c2d0
commit e2f20a1afe
5 changed files with 44 additions and 2 deletions

View File

@ -1630,7 +1630,8 @@ class WidgetAnnotation extends Annotation {
if ( if (
data.fieldName && data.fieldName &&
/\[\d+\]$/.test(data.fieldName) && /\[\d+\]$/.test(data.fieldName) &&
!dict.has("Kids") !dict.has("Kids") &&
dict.has("T")
) { ) {
data.baseFieldName = data.fieldName.substring( data.baseFieldName = data.fieldName.substring(
0, 0,

View File

@ -1711,7 +1711,7 @@ class PDFDocument {
name = name === "" ? partName : `${name}.${partName}`; name = name === "" ? partName : `${name}.${partName}`;
} }
if (!field.has("Kids") && /\[\d+\]$/.test(name)) { if (!field.has("Kids") && field.has("T") && /\[\d+\]$/.test(name)) {
// We've a terminal node: strip the index. // We've a terminal node: strip the index.
name = name.substring(0, name.lastIndexOf("[")); name = name.substring(0, name.lastIndexOf("["));
} }

View File

@ -160,6 +160,37 @@ describe("Checkbox annotation", () => {
); );
}); });
}); });
describe("bug1847733.pdf", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("bug1847733.pdf", "[data-annotation-id='18R']");
});
afterAll(async () => {
await closePages(pages);
});
it("must check the checkbox", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const selectors = [18, 30, 42, 54].map(
id => `[data-annotation-id='${id}R']`
);
for (const selector of selectors) {
await page.click(selector);
page.waitForTimeout(10);
}
for (const selector of selectors) {
await page.waitForFunction(
`document.querySelector("${selector} > :first-child").checked`
);
}
})
);
});
});
}); });
describe("Text widget", () => { describe("Text widget", () => {

View File

@ -0,0 +1,2 @@
https://github.com/mozilla/pdf.js/files/12290354/PDF.Form.4.pdf

View File

@ -8070,5 +8070,13 @@
"rounds": 1, "rounds": 1,
"type": "eq", "type": "eq",
"print": true "print": true
},
{
"id": "bug1847733",
"file": "pdfs/bug1847733.pdf",
"md5": "d2e167216493a50f732b4b3685a91792",
"rounds": 1,
"link": true,
"type": "other"
} }
] ]