mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
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:
parent
2b6d67b29a
commit
8ba71f09d7
3 changed files with 10 additions and 13 deletions
|
|
@ -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}\``; }
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}\``; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue