Skip to content

Commit

Permalink
Allow the use of quotes in set-cookie scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 13, 2023
1 parent 30a01d8 commit 7c562d0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ function setLocalStorageItemFn(
const unquoted = match && match[2] || normalized;
if ( trustedValues.includes(unquoted) === false ) {
if ( /^\d+$/.test(unquoted) === false ) { return; }
const integer = parseInt(unquoted, 10);
if ( integer > 32767 ) { return; }
const n = parseInt(unquoted, 10);
if ( n > 32767 ) { return; }
}
}

Expand Down Expand Up @@ -3418,16 +3418,17 @@ function setCookie(
'ok',
'on', 'off',
'true', 't', 'false', 'f',
'y', 'n',
'yes', 'no',
'yes', 'y', 'no', 'n',
'necessary', 'required',
];
if ( validValues.includes(value.toLowerCase()) === false ) {
if ( /^\d+$/.test(value) === false ) { return; }
const normalized = value.toLowerCase();
const match = /^("?)(.+)\1$/.exec(normalized);
const unquoted = match && match[2] || normalized;
if ( validValues.includes(unquoted) === false ) {
if ( /^\d+$/.test(unquoted) === false ) { return; }
const n = parseInt(value, 10);
if ( n > 15 ) { return; }
}
value = encodeURIComponent(value);

setCookieFn(
false,
Expand Down

0 comments on commit 7c562d0

Please sign in to comment.