Skip to content

Commit

Permalink
fix null guard
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 7, 2022
1 parent 639ab15 commit b3b8d29
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/helpers/cookie-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/scriptlets/set-cookie-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions src/scriptlets/set-cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b3b8d29

Please sign in to comment.