From 609c54458fd6d650465209c0bb081f3a1f815adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wr=C3=B3blewski?= Date: Thu, 23 May 2024 17:24:35 +0200 Subject: [PATCH] Update toRegExp --- src/helpers/string-utils.ts | 5 +++-- src/scriptlets/trusted-click-element.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/helpers/string-utils.ts b/src/helpers/string-utils.ts index 8ba9df4b8..6e939bab6 100644 --- a/src/helpers/string-utils.ts +++ b/src/helpers/string-utils.ts @@ -50,10 +50,11 @@ export const escapeRegExp = (str: string): string => str.replace(/[.*+?^${}()|[\ * if string contains valid regexp flags it will be converted to regexp with flags * TODO think about nested dependencies, but be careful with dependency loops * - * @param input literal string or regexp pattern; defaults to '' (empty string) + * @param rawInput literal string or regexp pattern; defaults to '' (empty string) * @returns regular expression; defaults to /.?/ */ -export const toRegExp = (input: RawStrPattern = ''): RegExp => { +export const toRegExp = (rawInput?: RawStrPattern | null): RegExp => { + const input = rawInput || ''; const DEFAULT_VALUE = '.?'; const FORWARD_SLASH = '/'; if (input === '') { diff --git a/src/scriptlets/trusted-click-element.ts b/src/scriptlets/trusted-click-element.ts index 056dbb6f9..3ce7f4c5e 100644 --- a/src/scriptlets/trusted-click-element.ts +++ b/src/scriptlets/trusted-click-element.ts @@ -196,7 +196,7 @@ export function trustedClickElement( // Avoid getting /.?/ result from toRegExp on undefined // as cookie may be set without value, // on which cookie parsing will return cookieKey:undefined pair - const valueMatch = parsedCookieMatches[key] ? toRegExp(parsedCookieMatches[key] || '') : null; + const valueMatch = parsedCookieMatches[key] ? toRegExp(parsedCookieMatches[key]) : null; const keyMatch = toRegExp(key); return cookieKeys.some((cookieKey) => {