Skip to content

Commit

Permalink
Merge pull request #12720 from calixteman/fix_co
Browse files Browse the repository at this point in the history
Be sure that CalculationOrder is either null or a non-empty array
  • Loading branch information
timvandermeij authored Dec 10, 2020
2 parents 85ab53f + 25bf504 commit 7097114
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,9 @@ class PDFDocument {
}

const ids = calculationOrder.filter(isRef).map(ref => ref.toString());
if (ids.length === 0) {
return shadow(this, "calculationOrderIds", null);
}
return shadow(this, "calculationOrderIds", ids);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/scripting_api/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class EventDispatcher {
}

calculateNow() {
if (this._calculationOrder.length === 0) {
if (!this._calculationOrder) {
return;
}
const first = this._calculationOrder[0];
Expand All @@ -160,7 +160,7 @@ class EventDispatcher {
}

runCalculate(source, event) {
if (this._calculationOrder.length === 0) {
if (!this._calculationOrder) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions test/unit/document_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ describe("document", function () {
acroForm.set("CO", []);
pdfDocument = getDocument(acroForm);
expect(pdfDocument.calculationOrderIds).toEqual(null);

acroForm.set("CO", ["1", "2"]);
pdfDocument = getDocument(acroForm);
expect(pdfDocument.calculationOrderIds).toEqual(null);

acroForm.set("CO", ["1", Ref.get(1, 0), "2"]);
pdfDocument = getDocument(acroForm);
expect(pdfDocument.calculationOrderIds).toEqual(["1R"]);
});

it("should get field objects array or null", async function () {
Expand Down

0 comments on commit 7097114

Please sign in to comment.