Skip to content

Commit

Permalink
fix(ShortcutManager): return empty string for invalid keycode during …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
vaibhavrajsingh2001 authored Apr 15, 2024
1 parent 20862e6 commit 58d75fc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utilities/ShortcutManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ function triggerShortcuts<CommandKeyword extends string>(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 ''
}

Expand Down

0 comments on commit 58d75fc

Please sign in to comment.