Skip to content

Commit 8ba71f0

Browse files
committed
Improve quote usage in filter options and scriptlets
Related feedback: uBlockOrigin/uBlock-issues#760 (comment) 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.
1 parent 2b6d67b commit 8ba71f0

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/js/scriptlet-filtering-core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const patchScriptlet = (content, arglist) => {
9999
};
100100

101101
const requote = s => {
102-
if ( /^(["'`]).+\1$|,/.test(s) === false ) { return s; }
102+
if ( /^(["'`]).*\1$|,|^$/.test(s) === false ) { return s; }
103103
if ( s.includes("'") === false ) { return `'${s}'`; }
104104
if ( s.includes('"') === false ) { return `"${s}"`; }
105105
if ( s.includes('`') === false ) { return `\`${s}\``; }

src/js/static-filtering-parser.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,18 +1477,15 @@ export class AstFilterParser {
14771477
if ( j === -1 ) { return end; }
14781478
if ( (j+1) === end ) { return end; }
14791479
for (;;) {
1480-
const before = s.charCodeAt(j-1);
1481-
if ( j !== start && before === 0x24 /* $ */ ) { return -1; }
1482-
const after = s.charCodeAt(j+1);
1483-
if (
1484-
after !== 0x29 /* ) */ &&
1485-
after !== 0x2F /* / */ &&
1486-
after !== 0x7C /* | */ &&
1487-
before !== 0x5C /* \ */
1488-
) {
1489-
return j;
1480+
const before = s.charAt(j-1);
1481+
if ( before === '$' ) { return -1; }
1482+
const after = s.charAt(j+1);
1483+
if ( ')/|'.includes(after) === false ) {
1484+
if ( before === '' || '"\'\\`'.includes(before) === false ) {
1485+
return j;
1486+
}
14901487
}
1491-
if ( j <= start ) { break; }
1488+
if ( j === start ) { break; }
14921489
j = s.lastIndexOf('$', j-1);
14931490
if ( j === -1 ) { break; }
14941491
}

src/js/static-net-filtering.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class LogData {
419419
}
420420

421421
static requote(s) {
422-
if ( /^(["'`]).+\1$|,/.test(s) === false ) { return s; }
422+
if ( /^\$|^(["'`]).*\1$|,/.test(s) === false ) { return s; }
423423
if ( s.includes("'") === false ) { return `'${s}'`; }
424424
if ( s.includes('"') === false ) { return `"${s}"`; }
425425
if ( s.includes('`') === false ) { return `\`${s}\``; }

0 commit comments

Comments
 (0)