Skip to content

Commit

Permalink
Ensure that the field value, for checkboxes, refers to an existing ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffleupagus committed Jul 14, 2021
1 parent a17bd13 commit 0265310
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 @@ -2075,6 +2075,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 @@ -952,6 +952,14 @@
"enableXfa": true,
"type": "eq"
},
{ "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 @@ -2192,8 +2192,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 @@ -2216,15 +2216,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 @@ -2239,14 +2239,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 @@ -2268,8 +2268,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 0265310

Please sign in to comment.