From 4b7f9a8d87ae26f190bcffd308db07c9512c5383 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 2 Aug 2024 21:49:00 +0200 Subject: [PATCH] Empty fields are 0 when using AFSimple_Calculate It fixes #18536 and #18532. --- src/scripting_api/aform.js | 6 ++-- test/integration/scripting_spec.mjs | 44 ++++++++++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/issue18536.pdf | Bin 0 -> 8351 bytes 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100755 test/pdfs/issue18536.pdf diff --git a/src/scripting_api/aform.js b/src/scripting_api/aform.js index d72e545223efe..74cd5a7c535b7 100644 --- a/src/scripting_api/aform.js +++ b/src/scripting_api/aform.js @@ -514,14 +514,12 @@ class AForm { } for (const child of field.getArray()) { const number = this.AFMakeNumber(child.value); - if (number !== null) { - values.push(number); - } + values.push(number ?? 0); } } if (values.length === 0) { - event.value = cFunction === "PRD" ? 1 : 0; + event.value = 0; return; } diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index f41c271b882ea..94e5f3a7e2e73 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -2466,4 +2466,48 @@ describe("Interaction", () => { ); }); }); + + describe("Compute product of different fields", () => { + let pages; + let otherPages; + + beforeAll(async () => { + otherPages = await Promise.all( + global.integrationSessions.map(async session => + session.browser.newPage() + ) + ); + pages = await loadAndWait("issue18536.pdf", getSelector("34R")); + }); + + afterAll(async () => { + await closePages(pages); + await Promise.all(otherPages.map(page => page.close())); + }); + + it("must check that the product are null", async () => { + await Promise.all( + pages.map(async ([browserName, page], i) => { + await waitForScripting(page); + + const inputSelector = getSelector("34R"); + await page.click(inputSelector); + await page.type(inputSelector, "123"); + await page.click(getSelector("28R")); + await page.waitForFunction( + `${getQuerySelector("36R")}.value !== "0"` + ); + + let text = await page.$eval(getSelector("30R"), el => el.value); + expect(text).withContext(`In ${browserName}`).toEqual("0"); + + text = await page.$eval(getSelector("35R"), el => el.value); + expect(text).withContext(`In ${browserName}`).toEqual("0"); + + text = await page.$eval(getSelector("36R"), el => el.value); + expect(text).withContext(`In ${browserName}`).toEqual("123"); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index dde1c01660e87..b353f8d31926d 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -659,3 +659,4 @@ !issue18360.pdf !issue18099_reduced.pdf !file_pdfjs_test.pdf +!issue18536.pdf diff --git a/test/pdfs/issue18536.pdf b/test/pdfs/issue18536.pdf new file mode 100755 index 0000000000000000000000000000000000000000..39121efe6ad52646995322a6eba730352b071662 GIT binary patch literal 8351 zcmeHM2~<9kqBDhp;WyFu_6g~$UqW95CVB&h+sez(3X(gglHyi!YDXZg;pyT z1sq$Ytro>TaVX*lT1Tiz)jFV-qU{rH)z&)K`kx!7sIldL>#g{jmyd)+gh%kjm}nXtX;9%g zDZp`zM?R>HU`Sw~9FD;a8cRCF#Yk(iNJm+)+-S5wDBJoy9zX-J0S37y9G)V_)$rsL z6v7}90<(p{6?z&q{YqMz$|E&3E%k)cAh+uA^D+X9czxdL8#>7K3r8thl**@!65T@( z6k|C1D^fo#df2q<7uNVWeJFy+{*E*%K(bR+C#GhLg0SQexSB>qXjDJHh*$}YN~5xo z9!%|l1$<(4Im9Q!$V1_H()dJ(AM~8Lsj01Lsi|_D;xK%sb3&cNkvD1S2dBn0)}$s*TM|?7MBs5O3A( zFx=qK*P9}z_upj47b}jPWD8XiMv0NoLm1Zzt_-&*R0@j%A_*ynV>2x}Ku0qaWPOZN zXh0i9tq)fG#XweP)bx-KwP9JP!CHO+T6zeOK}DdyQ;|Rb9{5Aqd5}skpDV@0!aQR2nuFlFZ_6U zm3%pepa}M#Bdzqk!HdUH=OBaoJ_$ZtcJZrG-pyS4#VM}td*_Vs7+3)f|8BlwbJFPX z+Y1wyXgBE6X}3MyM-TqBxtKXH)!TnY^4e>Q`@bFMcJt9UQ%-mVjAI1+&=%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