diff --git a/src/scripting_api/app.js b/src/scripting_api/app.js index acf1a7e22..74dba793d 100644 --- a/src/scripting_api/app.js +++ b/src/scripting_api/app.js @@ -447,6 +447,9 @@ class App extends PDFObject { cMsg = cMsg.cMsg; } cMsg = (cMsg || "").toString(); + if (!cMsg) { + return 0; + } nType = typeof nType !== "number" || isNaN(nType) || nType < 0 || nType > 3 ? 0 diff --git a/test/unit/scripting_spec.js b/test/unit/scripting_spec.js index 9ce2699d4..6246120df 100644 --- a/test/unit/scripting_spec.js +++ b/test/unit/scripting_spec.js @@ -607,6 +607,52 @@ describe("Scripting", function () { value = await myeval(`app.platform = "hello"`); expect(value).toEqual("app.platform is read-only"); }); + + it("shouldn't display an alert", async () => { + const refId = getId(); + const data = { + objects: { + field: [ + { + id: refId, + value: "", + actions: { + Validate: [`app.alert(event.value);`], + }, + type: "text", + name: "MyField", + }, + ], + }, + appInfo: { language: "en-US", platform: "Linux x86_64" }, + calculationOrder: [], + dispatchEventName: "_dispatchMe", + }; + + sandbox.createSandbox(data); + await sandbox.dispatchEventInSandbox({ + id: refId, + value: "hello", + name: "Keystroke", + willCommit: true, + }); + expect(send_queue.has("alert")).toEqual(true); + expect(send_queue.get("alert")).toEqual({ + command: "alert", + value: "hello", + }); + send_queue.delete(refId); + send_queue.delete("alert"); + + await sandbox.dispatchEventInSandbox({ + id: refId, + value: "", + name: "Keystroke", + willCommit: true, + }); + expect(send_queue.has("alert")).toEqual(false); + send_queue.delete(refId); + }); }); describe("AForm", function () {