ghostery/adblocker

Scriptlet arguments are parsed incorrectly

romkaC opened this issue · 1 comments

romkaC commented

The rule found in the uBlock filterlist is processed incorrectly with the package v1.26.8 and it breaks amazon.com product pages.

Rule:

www.amazon.co.jp,www.amazon.com,www.amazon.de##+js(xml-prune, xpath(//*[name()="Period"][.//*[@value="Ad"]] | //*[name()="Period"]/@start), [value="Ad"], .mpd)

Added a simple test case to check parsing results:

  it('parses amazon scriptlet arguments', () => {
    const [scriptlet, expected] = [
      'xml-prune, xpath(//*[name()="Period"][.//*[@value="Ad"]] | //*[name()="Period"]/@start), [value="Ad"], .mpd',
      {
        name: 'xml-prune',
        args: [
          'xpath(//*[name()="Period"][.//*[@value="Ad"]] | //*[name()="Period"]/@start)',
          '[value="Ad"]',
          '.mpd',
        ],
      },
    ];

    expect(CosmeticFilter.parse(`foo.com##+js(${scriptlet})`)?.parseScript(), scriptlet).to.eql(
      expected,
    );
  });

The result is that all the arguments are parsed as a single string, instead of being split to 3 different strings.

scriptlets arguments parsing
       parses amazon scriptlet arguments:

      xml-prune, xpath(//*[name()="Period"][.//*[@value="Ad"]] | //*[name()="Period"]/@start), [value="Ad"], .mpd
      + expected - actual

       {
         "args": [
      -    "xpath(//*[name()=\"Period\"][.//*[@value=\"Ad\"]] | //*[name()=\"Period\"]/@start), [value=\"Ad\"], .mpd"
      +    "xpath(//*[name()=\"Period\"][.//*[@value=\"Ad\"]] | //*[name()=\"Period\"]/@start)"
      +    "[value=\"Ad\"]"
      +    ".mpd"
         ]
         "name": "xml-prune"
       }
romkaC commented

seems to be fixed with #3558