Improve quote usage in filter options and scriptlets

Related feedback:
https://github.com/uBlockOrigin/uBlock-issues/issues/760#issuecomment-2540436382

Using quotes in filter option values is meant to remove ambiguity
when the value contains special characters. This was not working when
the value started with `$`. For example, fixes usage of quotes in:

  $removeparam='$deep_link'

Also, fixed logger output for scriptlets using empty parameters
in quotes.
This commit is contained in:
Raymond Hill 2024-12-13 10:54:01 -05:00
parent 2b6d67b29a
commit 8ba71f09d7
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
3 changed files with 10 additions and 13 deletions

View file

@ -99,7 +99,7 @@ const patchScriptlet = (content, arglist) => {
};
const requote = s => {
if ( /^(["'`]).+\1$|,/.test(s) === false ) { return s; }
if ( /^(["'`]).*\1$|,|^$/.test(s) === false ) { return s; }
if ( s.includes("'") === false ) { return `'${s}'`; }
if ( s.includes('"') === false ) { return `"${s}"`; }
if ( s.includes('`') === false ) { return `\`${s}\``; }

View file

@ -1477,18 +1477,15 @@ export class AstFilterParser {
if ( j === -1 ) { return end; }
if ( (j+1) === end ) { return end; }
for (;;) {
const before = s.charCodeAt(j-1);
if ( j !== start && before === 0x24 /* $ */ ) { return -1; }
const after = s.charCodeAt(j+1);
if (
after !== 0x29 /* ) */ &&
after !== 0x2F /* / */ &&
after !== 0x7C /* | */ &&
before !== 0x5C /* \ */
) {
return j;
const before = s.charAt(j-1);
if ( before === '$' ) { return -1; }
const after = s.charAt(j+1);
if ( ')/|'.includes(after) === false ) {
if ( before === '' || '"\'\\`'.includes(before) === false ) {
return j;
}
}
if ( j <= start ) { break; }
if ( j === start ) { break; }
j = s.lastIndexOf('$', j-1);
if ( j === -1 ) { break; }
}

View file

@ -419,7 +419,7 @@ class LogData {
}
static requote(s) {
if ( /^(["'`]).+\1$|,/.test(s) === false ) { return s; }
if ( /^\$|^(["'`]).*\1$|,/.test(s) === false ) { return s; }
if ( s.includes("'") === false ) { return `'${s}'`; }
if ( s.includes('"') === false ) { return `"${s}"`; }
if ( s.includes('`') === false ) { return `\`${s}\``; }