Skip to content

Commit f0a8a79

Browse files
Merge pull request #19177 from calixteman/issue19171
Avoid to display an alert or a confirm dialog if the message is empty
2 parents f180de4 + d1db8d6 commit f0a8a79

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/scripting_api/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ class App extends PDFObject {
447447
cMsg = cMsg.cMsg;
448448
}
449449
cMsg = (cMsg || "").toString();
450+
if (!cMsg) {
451+
return 0;
452+
}
450453
nType =
451454
typeof nType !== "number" || isNaN(nType) || nType < 0 || nType > 3
452455
? 0

test/unit/scripting_spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,52 @@ describe("Scripting", function () {
607607
value = await myeval(`app.platform = "hello"`);
608608
expect(value).toEqual("app.platform is read-only");
609609
});
610+
611+
it("shouldn't display an alert", async () => {
612+
const refId = getId();
613+
const data = {
614+
objects: {
615+
field: [
616+
{
617+
id: refId,
618+
value: "",
619+
actions: {
620+
Validate: [`app.alert(event.value);`],
621+
},
622+
type: "text",
623+
name: "MyField",
624+
},
625+
],
626+
},
627+
appInfo: { language: "en-US", platform: "Linux x86_64" },
628+
calculationOrder: [],
629+
dispatchEventName: "_dispatchMe",
630+
};
631+
632+
sandbox.createSandbox(data);
633+
await sandbox.dispatchEventInSandbox({
634+
id: refId,
635+
value: "hello",
636+
name: "Keystroke",
637+
willCommit: true,
638+
});
639+
expect(send_queue.has("alert")).toEqual(true);
640+
expect(send_queue.get("alert")).toEqual({
641+
command: "alert",
642+
value: "hello",
643+
});
644+
send_queue.delete(refId);
645+
send_queue.delete("alert");
646+
647+
await sandbox.dispatchEventInSandbox({
648+
id: refId,
649+
value: "",
650+
name: "Keystroke",
651+
willCommit: true,
652+
});
653+
expect(send_queue.has("alert")).toEqual(false);
654+
send_queue.delete(refId);
655+
});
610656
});
611657

612658
describe("AForm", function () {

0 commit comments

Comments
 (0)