From 462569583f2f8c7e116ca971aa02fa0133247f40 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 27 Apr 2021 16:26:32 +1000 Subject: [PATCH] Make command handling more robust --- web-chat/src/command.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web-chat/src/command.ts b/web-chat/src/command.ts index 2741b124e2..3034c686ec 100644 --- a/web-chat/src/command.ts +++ b/web-chat/src/command.ts @@ -84,7 +84,7 @@ export default function handleCommand( setNick: (nick: string) => void ): { command: string; response: string[] } { let response: string[] = []; - const args = input.split(' '); + const args = parseInput(input); const command = args.shift()!; switch (command) { case '/help': @@ -107,3 +107,8 @@ export default function handleCommand( } return { command, response }; } + +export function parseInput(input: string): string[] { + const clean = input.trim().replaceAll(/\s\s+/g, ' '); + return clean.split(' '); +}