sanitization around numerical inputs

master
j 2024-04-18 00:44:47 -04:00
parent 46cfe43c75
commit 0107af0a7b
1 changed files with 10 additions and 2 deletions

View File

@ -4,6 +4,7 @@ export class CommentParser {
/** /**
* Parses commands from the body of a single comment triggered by !!Oregon. * Parses commands from the body of a single comment triggered by !!Oregon.
* If the comment contains only "!!Oregon", it treats it as a "start" command. * If the comment contains only "!!Oregon", it treats it as a "start" command.
* Additionally, if the command or any argument is a number, it is floored.
* @param comment A single Comment object to be processed. * @param comment A single Comment object to be processed.
* @returns An object containing the command and its arguments, if any. * @returns An object containing the command and its arguments, if any.
*/ */
@ -15,8 +16,15 @@ export class CommentParser {
if (match) { if (match) {
// If the command is exactly "!!Oregon" with no additional command word, set command to "start" // If the command is exactly "!!Oregon" with no additional command word, set command to "start"
const command = match[1] ? match[1].toLowerCase() : "start"; let command = match[1] ? match[1].toLowerCase() : "start";
const args = match[2] ? match[2].split(' ').map(arg => arg.trim()) : []; const numCommand = Number(command);
if (!isNaN(numCommand) && isFinite(numCommand)) {
command = Math.floor(numCommand).toString();
}
const args = match[2] ? match[2].split(' ').map(arg => {
const numArg = Number(arg);
return !isNaN(numArg) && isFinite(numArg) ? Math.floor(numArg).toString() : arg;
}) : [];
return { command, args }; return { command, args };
} }