From 7b10359592dde4b47e7d72e38bc69df0b53e7cc8 Mon Sep 17 00:00:00 2001 From: Vaibhav Raj Singh Date: Tue, 16 Apr 2024 00:30:03 +0530 Subject: [PATCH] fix(ShortcutManager): return empty string for invalid keycode during normalization [KHCP-11186] (#2137) Datadog reported that in `normalizeKeyCode` method, `.replace` was being accessed on `undefined`. So added a check to early return with an empty string in case the parameter passed to the method is `undefined`, or an invalid string. Extended explanation [here](https://konghq.atlassian.net/browse/KHCP-11186?focusedCommentId=129798) --- src/utilities/ShortcutManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utilities/ShortcutManager.ts b/src/utilities/ShortcutManager.ts index 42e7bd7b78..e134323ee3 100644 --- a/src/utilities/ShortcutManager.ts +++ b/src/utilities/ShortcutManager.ts @@ -118,8 +118,8 @@ function triggerShortcuts(event: KeyboardEvent, k } function normalizeKeyCode(code: string): string { - // Returns relevant modifier keys as the empty string which is going to be filtered out. - if (MODIFIER_KEY_CODES.includes(code)) { + // If keycode is a relevant modifier key or an invalid string, return empty string. + if (!code || MODIFIER_KEY_CODES.includes(code)) { return '' }