From 7c562d0c5c72f1f92bcae351422b0364e6f0e037 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 12 Nov 2023 19:26:05 -0500 Subject: [PATCH] Allow the use of quotes in `set-cookie` scriptlet Related discussion: https://github.com/uBlockOrigin/uAssets/issues/20630#issuecomment-1807260357 --- assets/resources/scriptlets.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index d6a2d2d5e..547c97988 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -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; } } } @@ -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,