From ca95264e8bc353e4a72cb46c1a1c397d2d8b8b23 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Wed, 11 Sep 2024 17:19:34 +0200 Subject: [PATCH] [JS] Correctly format floating numbers when they're close to an integer (bug 1918115) --- src/scripting_api/util.js | 7 ++++++- test/integration/scripting_spec.mjs | 28 ++++++++++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/bug1918115.pdf | Bin 0 -> 13150 bytes 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 test/pdfs/bug1918115.pdf diff --git a/src/scripting_api/util.js b/src/scripting_api/util.js index 5220c5b64bc65..551a3fb600797 100644 --- a/src/scripting_api/util.js +++ b/src/scripting_api/util.js @@ -153,7 +153,12 @@ class Util extends PDFObject { ? Math.abs(arg - intPart).toFixed(nPrecision) : Math.abs(arg - intPart).toString(); if (decPart.length > 2) { - decPart = `${decimalSep}${decPart.substring(2)}`; + if (/^1\.0+$/.test(decPart)) { + intPart += Math.sign(arg); + decPart = `${decimalSep}${decPart.split(".")[1]}`; + } else { + decPart = `${decimalSep}${decPart.substring(2)}`; + } } else { if (decPart === "1") { intPart += Math.sign(arg); diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index e472a810cef39..57b0c52e65112 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -2468,4 +2468,32 @@ describe("Interaction", () => { ); }); }); + + describe("Correctly format numbers", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("bug1918115.pdf", getSelector("33R")); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the computed value is correct", async () => { + await Promise.all( + pages.map(async ([browserName, page], i) => { + await waitForScripting(page); + + const inputSelector = getSelector("33R"); + await page.click(inputSelector); + await page.type(inputSelector, "7"); + await page.click(getSelector("34R")); + await page.waitForFunction( + `${getQuerySelector("35R")}.value === "324,00"` + ); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 01dd1d125d352..fc0f6e0e8936b 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -667,3 +667,4 @@ !bug1708040.pdf !issue18694.pdf !issue18693.pdf +!bug1918115.pdf diff --git a/test/pdfs/bug1918115.pdf b/test/pdfs/bug1918115.pdf new file mode 100755 index 0000000000000000000000000000000000000000..927fd12bf11f4ec645ed6bb41609f1632f1be9d7 GIT binary patch literal 13150 zcmeHucUV)~(l@;c(iABwktWj813@|g>AfmF2@r$?lF&g#sZs@%B49y^V4;d4h$xD5 z>53po5u~Fcf`IQvJx9(x+;i`FzVCg$?~fB6lI*=_X3hN8%*vXzW{I0%v}K`kC=T(F z(e^G5HYfrF0g+rhIFyvY1_UDBnM?@6<3Lcb0SF3*A|YU75EKR00x6)N3ScAPz6A&h zQ$Rq$I-p}91R4f{Dj@7tR53f-0c=1>1lS_b8xOWI!@Gj5 zk3m5I1^@ySDjDzW#lhzO#>EB4<>chzltCxPj}2pZqQ%w6U$02(f({c?vvUaLnwHlQ zVbk$;KaGQj)zb?wNoYq#fLNKHg@HEU4ku~3oM@7h*i<>#07!od{Ru9G>P)5vknye@ zY!D7Mad9nUZ4S0S1OD?42ODzJte<_m9iV`P@ZXF^BY>V(fP>8eRKQjsH2Mz~IXMlx zIyrs7(a_z$z+P}lAljB+f$z#$vL=*Xa~C~laGl{@W^llS-8hd^!OHXYA)1R$I46@Y z3|9q+^iW>Get9Sq^$Qer zB9TO;fMDqF^qM3h6;Ir}{=u(FCV6X+0**oCAfU~E6ch%$%cFsJd$1wkuFn7VDd69L zq~8=V!&6AUWGsHu1!}B(+++xs{=+fA#5fHtAzOe7=ZbG<;$7W#v@Ny_b0c_|@B@=*9_-WuK z`IhhY;B6Gw!F&3F;LuIQ|DCetzAn_w0NHHwXQ&vvc;K{tyZv7-aLIH5-vl!-5U`T?L?zEnER9Zfr0R zN)8DSS>V_t;SiXN0^|_L!h=oA0+6L;sL8gSgKhfKPY3%Okiq^QVq1H1vlIUhaoNs} z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