Skip to content

Commit

Permalink
Merge pull request #13735 from Snuffleupagus/bug-1720411
Browse files Browse the repository at this point in the history
Ensure that the field value, for checkboxes, refers to an existing appearance state (bug 1720411)
  • Loading branch information
timvandermeij authored Jul 18, 2021
2 parents 668c58d + da808ae commit 07955fa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
// The /Off appearance is optional.
exportValues.push("Off");
}
// Don't use a "V" entry pointing to a non-existent appearance state,
// see e.g. bug1720411.pdf where it's an *empty* Name-instance.
if (!exportValues.includes(this.data.fieldValue)) {
this.data.fieldValue = null;
}
if (exportValues.length !== 2) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/bug1720411.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9231160
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,14 @@
}
}
},
{ "id": "bug1720411",
"file": "pdfs/bug1720411.pdf",
"md5": "a3a3616d89d475b000373025fbd24735",
"rounds": 1,
"link": true,
"type": "eq",
"forms": true
},
{ "id": "xfa_bug1718740",
"file": "pdfs/xfa_bug1718740.pdf",
"md5": "fab4277f2c70fd1edb35f597f5fe6819",
Expand Down
24 changes: 12 additions & 12 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2198,8 +2198,8 @@ describe("annotation", function () {
});

it("should handle checkboxes with export value", async function () {
buttonWidgetDict.set("V", Name.get("1"));
buttonWidgetDict.set("DV", Name.get("2"));
buttonWidgetDict.set("V", Name.get("Checked"));
buttonWidgetDict.set("DV", Name.get("Off"));

const appearanceStatesDict = new Dict();
const normalAppearanceDict = new Dict();
Expand All @@ -2222,15 +2222,15 @@ describe("annotation", function () {
);
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(true);
expect(data.fieldValue).toEqual("1");
expect(data.defaultFieldValue).toEqual("2");
expect(data.fieldValue).toEqual("Checked");
expect(data.defaultFieldValue).toEqual("Off");
expect(data.radioButton).toEqual(false);
expect(data.exportValue).toEqual("Checked");
});

it("should handle checkboxes without export value", async function () {
buttonWidgetDict.set("V", Name.get("1"));
buttonWidgetDict.set("DV", Name.get("2"));
buttonWidgetDict.set("V", Name.get("Checked"));
buttonWidgetDict.set("DV", Name.get("Off"));

const buttonWidgetRef = Ref.get(124, 0);
const xref = new XRefMock([
Expand All @@ -2245,14 +2245,14 @@ describe("annotation", function () {
);
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(true);
expect(data.fieldValue).toEqual("1");
expect(data.defaultFieldValue).toEqual("2");
expect(data.fieldValue).toEqual("Checked");
expect(data.defaultFieldValue).toEqual("Off");
expect(data.radioButton).toEqual(false);
});

it("should handle checkboxes without /Off appearance", async function () {
buttonWidgetDict.set("V", Name.get("1"));
buttonWidgetDict.set("DV", Name.get("2"));
buttonWidgetDict.set("V", Name.get("Checked"));
buttonWidgetDict.set("DV", Name.get("Off"));

const appearanceStatesDict = new Dict();
const normalAppearanceDict = new Dict();
Expand All @@ -2274,8 +2274,8 @@ describe("annotation", function () {
);
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(true);
expect(data.fieldValue).toEqual("1");
expect(data.defaultFieldValue).toEqual("2");
expect(data.fieldValue).toEqual("Checked");
expect(data.defaultFieldValue).toEqual("Off");
expect(data.radioButton).toEqual(false);
expect(data.exportValue).toEqual("Checked");
});
Expand Down

0 comments on commit 07955fa

Please sign in to comment.