Skip to content

Commit 536987b

Browse files
fix: fix getActions empty key and action.payload falsy check in api.js
- getActions: use 'match() || []' with 'if (n &&)' guard to skip empty strings produced by case-pattern matches with $1 substitution - getExternalApiByGuessing: guard against empty keys with 'if (key)' - answerNotifyApi: use 'in' operator instead of truthy check so falsy payloads like 0 are not skipped (fixes PAGE_SELECT page 0)
1 parent 845d464 commit 536987b

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

API/api.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ const express = require("express");
1616
const getActions = (content) => {
1717
const re = /notification ===? (?:"|')([A-Z_-]+?)(?:"|')|case (?:"|')([A-Z_-]+)(?:"|')/g;
1818
const availableActions = [];
19-
if (re.test(content)) {
20-
for (const match of content.match(re)) {
21-
const n = match.replaceAll(re, "$1");
22-
if (![
23-
"ALL_MODULES_STARTED",
24-
"DOM_OBJECTS_CREATED",
25-
"KEYPRESS",
26-
"MODULE_DOM_CREATED",
27-
"KEYPRESS_MODE_CHANGED",
28-
"USER_PRESENCE"
29-
].includes(n)) {
30-
availableActions.push(n);
31-
}
19+
for (const match of content.match(re) || []) {
20+
const n = match.replaceAll(re, "$1");
21+
if (n && ![
22+
"ALL_MODULES_STARTED",
23+
"DOM_OBJECTS_CREATED",
24+
"KEYPRESS",
25+
"MODULE_DOM_CREATED",
26+
"KEYPRESS_MODE_CHANGED",
27+
"USER_PRESENCE"
28+
].includes(n)) {
29+
availableActions.push(n);
3230
}
3331
}
3432
return availableActions;
@@ -71,7 +69,10 @@ module.exports = {
7169
const actionsGuess = {};
7270

7371
for (const a of moduleActions) {
74-
actionsGuess[a.replaceAll(/[-_]/g, "").toLowerCase()] = {notification: a, guessed: true};
72+
const key = a.replaceAll(/[-_]/g, "").toLowerCase();
73+
if (key) {
74+
actionsGuess[key] = {notification: a, guessed: true};
75+
}
7576
}
7677

7778
if (module_.module in this.externalApiRoutes) {
@@ -516,8 +517,10 @@ module.exports = {
516517
if (request.method === "POST" && request.body !== undefined) {
517518
payload = typeof payload === "object" ? {...payload, ...request.body} : {param: payload, ...request.body};
518519
}
519-
if (action && action.payload) {
520-
payload = typeof payload === "object" ? {...payload, ...action.payload} : {param: payload, ...action.payload};
520+
if (action && "payload" in action) {
521+
payload = typeof payload === "object" && typeof action.payload === "object"
522+
? {...payload, ...action.payload}
523+
: action.payload;
521524
}
522525

523526
if ("action" in query && query.action == "DELAYED") {

0 commit comments

Comments
 (0)