From b3b8d29a58e80fde6042a8c235b5346edb6191aa Mon Sep 17 00:00:00 2001 From: Stanislav A Date: Mon, 7 Nov 2022 19:28:04 +0300 Subject: [PATCH] fix null guard --- src/helpers/cookie-utils.js | 4 ---- src/scriptlets/set-cookie-reload.js | 8 ++++++++ src/scriptlets/set-cookie.js | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/helpers/cookie-utils.js b/src/helpers/cookie-utils.js index ee95c8a9..a7532cab 100644 --- a/src/helpers/cookie-utils.js +++ b/src/helpers/cookie-utils.js @@ -38,10 +38,6 @@ export const getCookiePath = (rawPath) => { */ export const concatCookieNameValuePath = (rawName, rawValue, rawPath) => { const log = console.log.bind(console); // eslint-disable-line no-console - if (rawValue === null) { - log(`Invalid cookie value: '${rawValue}'`); - return null; - } if (!isValidCookieRawPath(rawPath)) { log(`Invalid cookie path: '${rawPath}'`); return null; diff --git a/src/scriptlets/set-cookie-reload.js b/src/scriptlets/set-cookie-reload.js index 3994e67d..958bac3c 100644 --- a/src/scriptlets/set-cookie-reload.js +++ b/src/scriptlets/set-cookie-reload.js @@ -50,7 +50,15 @@ export function setCookieReload(source, name, value, path = '/') { return; } + // eslint-disable-line no-console + const log = console.log.bind(console); + const validValue = getLimitedCookieValue(value); + if (validValue === null) { + log(`Invalid cookie value: '${validValue}'`); + return; + } + const cookieData = concatCookieNameValuePath(name, validValue, path); if (cookieData) { diff --git a/src/scriptlets/set-cookie.js b/src/scriptlets/set-cookie.js index d12669a1..7815b6ab 100644 --- a/src/scriptlets/set-cookie.js +++ b/src/scriptlets/set-cookie.js @@ -46,7 +46,15 @@ import { */ /* eslint-enable max-len */ export function setCookie(source, name, value, path = '/') { + // eslint-disable-line no-console + const log = console.log.bind(console); + const validValue = getLimitedCookieValue(value); + if (validValue === null) { + log(`Invalid cookie value: '${validValue}'`); + return; + } + const cookieData = concatCookieNameValuePath(name, validValue, path); if (cookieData) {