From 25bf504ff5239e6aa6eb9b3e28e661d2bf93bc56 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 10 Dec 2020 16:02:11 +0100 Subject: [PATCH] Be sure that CalculationOrder is either null or a non-empty array --- src/core/document.js | 3 +++ src/scripting_api/event.js | 4 ++-- test/unit/document_spec.js | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/document.js b/src/core/document.js index 1cce067abbf93..4736a2839cfa1 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -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); } } diff --git a/src/scripting_api/event.js b/src/scripting_api/event.js index f96b0f75717fe..542f16121cc6d 100644 --- a/src/scripting_api/event.js +++ b/src/scripting_api/event.js @@ -150,7 +150,7 @@ class EventDispatcher { } calculateNow() { - if (this._calculationOrder.length === 0) { + if (!this._calculationOrder) { return; } const first = this._calculationOrder[0]; @@ -160,7 +160,7 @@ class EventDispatcher { } runCalculate(source, event) { - if (this._calculationOrder.length === 0) { + if (!this._calculationOrder) { return; } diff --git a/test/unit/document_spec.js b/test/unit/document_spec.js index 57ab015421b6f..cde9f5105f787 100644 --- a/test/unit/document_spec.js +++ b/test/unit/document_spec.js @@ -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 () {