Skip to content

Commit

Permalink
Avoid to display an alert or a confirm dialog if the message is empty
Browse files Browse the repository at this point in the history
It fixes #19171.
  • Loading branch information
calixteman committed Dec 5, 2024
1 parent f180de4 commit d1db8d6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/scripting_api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions test/unit/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit d1db8d6

Please sign in to comment.