Skip to content

Commit

Permalink
Heuristic to prevent too eager argument type classification
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Oct 28, 2023
1 parent dbeddfa commit 103f5e9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/adblocker/src/filters/cosmetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,13 @@ export default class CosmeticFilter implements IFilter {
if (inArgument === false) {
if (char === ' ') {
// ignore
} else if (char === '"') {
} else if (char === '"' && selector.indexOf('"', index + 1) > 0) {
inDoubleQuotes = true;
} else if (char === "'") {
} else if (char === "'" && selector.indexOf("'", index + 1) > 0) {
inSingleQuotes = true;
} else if (char === '{') {
} else if (char === '{' && selector.indexOf('}', index + 1) > 0) {
objectNesting += 1;
} else if (char === '/') {
} else if (char === '/' && selector.indexOf('/', index + 1) > 0) {
inRegexp = true;
} else {
inArgument = true;
Expand Down
46 changes: 46 additions & 0 deletions packages/adblocker/test/parsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,52 @@ describe('scriptlets arguments parsing', () => {

it('complex', () => {
for (const [scriptlet, expected] of [
[
'script-name, {x, y',
{
name: 'script-name',
args: ['{x', 'y'],
},
],
[
'script-name, "x, y',
{
name: 'script-name',
args: ['"x', 'y'],
},
],
[
"script-name, 'x, y",
{
name: 'script-name',
args: ["'x", 'y'],
},
],
[
'script-name, /x, y',
{
name: 'script-name',
args: ['/x', 'y'],
},
],
[
'xml-prune,a/b,///,,c',
{
name: 'xml-prune',
args: ['a/b', '///', '', 'c'],
},
],
[
`xml-prune, xpath(//*[name()="MPD"]/@mediaPresentationDuration | //*[name()="Period"][.//*[name()="BaseURL" and contains(text()\\,'/ads-')]] | //*[name()="Period"]/@start), Period[id^="Ad"i], .mpd`,
{
name: 'xml-prune',
args: [
`xpath(//*[name()="MPD"]/@mediaPresentationDuration | //*[name()="Period"][.//*[name()="BaseURL" and contains(text()\\,'/ads-')]] | //*[name()="Period"]/@start)`,
'Period[id^="Ad"i]',
'.mpd',
],
},
],
[
'xml-prune,a/b,,c',
{
Expand Down

0 comments on commit 103f5e9

Please sign in to comment.