1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00
uBlock/platform
Raymond Hill a71b71e4c8
New cosmetic filter parser using CSSTree library
The new parser no longer uses the browser DOM to validate
that a cosmetic filter is valid or not, this is now done
through a JS library, CSSTree.

This means filter list authors will have to be more careful
to ensure that a cosmetic filter is really valid, as there is
no more guarantee that a cosmetic filter which works for a
given browser/version will still work properly on another
browser, or different version of the same browser.

This change has become necessary because of many reasons,
one of them being the flakiness of the previous parser as
exposed by many issues lately:

- https://github.com/uBlockOrigin/uBlock-issues/issues/2262
- https://github.com/uBlockOrigin/uBlock-issues/issues/2228

The new parser introduces breaking changes, there was no way
to do otherwise. Some current procedural cosmetic filters will
be shown as invalid with this change. This occurs because the
CSSTree library gets confused with some syntax which was
previously allowed by the previous parser because it was more
permissive.

Mainly the issue is with the arguments passed to some procedural
cosmetic filters, and these issues can be solved as follow:

Use quotes around the argument. You can use either single or
double-quotes, whichever is most convenient. If your argument
contains a single quote, use double-quotes, and vice versa.

Additionally, try to escape a quote inside an argument using
backslash. THis may work, but if not, use quotes around the
argument.

When the parser encounter quotes around an argument, it will
discard them before trying to process the argument, same with
escaped quotes inside the argument. Examples:

Breakage:

    ...##^script:has-text(toscr')

Fix:

    ...##^script:has-text(toscr\')

Breakage:

    ...##:xpath(//*[contains(text(),"VPN")]):upward(2)

Fix:

    ...##:xpath('//*[contains(text(),"VPN")]'):upward(2)

There are not many filters which break in the default set of
filter lists, so this should be workable for default lists.

Unfortunately those fixes will break the filter for previous
versions of uBO since these to not deal with quoted argument.
In such case, it may be necessary to keep the previous filter,
which will be discarded as broken on newer version of uBO.

THis was a necessary change as the old parser was becoming
more and more flaky after being constantly patched for new
cases arising, The new parser should be far more robust and
stay robist through expanding procedural cosmetic filter
syntax.

Additionally, in the MV3 version, filters are pre-compiled
using a Nodejs script, i.e. outside the browser, so validating
cosmetic filters using a live DOM no longer made sense.

This new parser will have to be tested throughly before stable
release.
2022-09-23 16:03:13 -04:00
..
browser Convert publicsuffixlist.js into an ES module (#3846) 2021-08-23 09:42:27 -04:00
chromium Do not block root document at launch in Chromium-based browsers 2022-03-30 12:15:44 -04:00
common New cosmetic filter parser using CSSTree library 2022-09-23 16:03:13 -04:00
dig Fix dig-snfe modifiers to properly detect changes in results 2021-12-06 08:01:05 -05:00
firefox Add command to toggle cosmetic filtering 2022-02-22 08:44:09 -05:00
mv3 New cosmetic filter parser using CSSTree library 2022-09-23 16:03:13 -04:00
nodejs Add test to detect case of improper deserialization 2022-01-12 09:03:38 -05:00
npm Add experimental mv3 version 2022-09-06 13:47:52 -04:00
opera Add command to toggle cosmetic filtering 2022-02-22 08:44:09 -05:00
safari Clarify that the code base was really old and obsolete 2019-09-22 09:57:38 -04:00
thunderbird Fix popup panel for Thunderbird 2022-06-18 11:18:27 -04:00