Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape quotes (' and ") in arguments of :contains in lists for uBO #156

Open
Yuki2718 opened this issue Nov 13, 2022 · 9 comments
Open

Escape quotes (' and ") in arguments of :contains in lists for uBO #156

Yuki2718 opened this issue Nov 13, 2022 · 9 comments
Assignees

Comments

@Yuki2718
Copy link

Due to new cosmetic filter parser, uBO requires quotes in arguments to be escapsed: gorhill/uBlock@a71b71e

An example that needs the fix is thetimestribune.com#?##tncms-region-option-rail-top-one > .tncms-block:has(> .block-title:contains(This Week's Circulars)) in Base filter.

Yuki2718 referenced this issue in uBlockOrigin/uAssets Nov 13, 2022
@Yuki2718 Yuki2718 changed the title Escape quotes (' or ") in lists for uBO Escape quotes (' or ") in arguments of cosmetic filters in lists for uBO Nov 13, 2022
@Yuki2718
Copy link
Author

Yuki2718 commented Nov 13, 2022

Probably only :contains will be affected in AG lists as I don't see :xpath usage, but if :xpath is used escape won't work and needs to be wrapped by another quote.

@Yuki2718 Yuki2718 changed the title Escape quotes (' or ") in arguments of cosmetic filters in lists for uBO Escape quotes (' and ") in arguments of :contains in lists for uBO Nov 13, 2022
@ameshkov
Copy link
Member

CC @slavaleleka

@Alex-302
Copy link
Member

@Yuki2718
Copy link
Author

Yuki2718 commented Nov 15, 2022

@Alex-302 It's totally different. The PR was about an uBO issue that will eventually be fixed but the problem here is permanent change of uBO.
BTW AG has been compatible with most of uBO syntax, so I wonder if it's possible for AG to be compatible with has-text with escape in some way.

@scripthunter7
Copy link
Member

scripthunter7 commented Feb 23, 2023

@Yuki2718 FYI: We have created the ECSSTree library, which is fully backwards compatible with basic CSSTree, but thanks to re-tokenization it can parse the edge case you mentioned and many other cases as well. You can find it at the following link: https://github.com/AdguardTeam/ecsstree

Related: uBlockOrigin/uBlock-issues#2328

@krystian3w
Copy link

krystian3w commented Feb 24, 2023

Also a little outdated is escape method, now works only in uBo:

example.org#?##A > .B:has(> .C:contains("This Week's Circulars"))
!
! shorter fake selectors to avoid horizontal scroll
!
example.com#?##D:contains('French "fo paux" is abused')

to avoid regex syntax for that as long uBo consider switch to ECSSTree.

Same protection needed orphaned [ ] { } ( ) if was copied to :contains() (when it is unfavorable to copy a long string so that the parenthesis is always closed).

@scripthunter7
Copy link
Member

Same protection needed orphaned ( )

See AdguardTeam/ecsstree#11

@krystian3w
Copy link

I'm curious if ECSSTree is used to compile filters in the "/ublock/" directory - if that is, the AdGuard filter problem fixed outside of FiltersCompiler / coreLibs (it is possible that here almost never) / tsurlfilter / FiltersRegistry.

Quickly I can no longer find any filters what would have ' " in contains (simple regex can fail for contains with orphaned bracket).

(I did the same myself with one detection of incompatible filter - for me it was enough to check less characters)

The one from the demo I think someone has already rewritten/removed by hand (But can be cumbersome for new cases).

@scripthunter7
Copy link
Member

AdGuard filter problem

I don't think this is a "problem" of AdGuard filters only, but a more general problem, since this syntax is used in all adblockers, as far as I know. It's simply that CSSTree's tokenizer doesn't support this syntax (for obvious reasons). CSSTree is an excellent library for various purposes, I have been experimenting with it since June 2022, that's why ECSSTree was created to solve these annoying edge cases. I tested ECSSTree on the entire AG Filters Registry and the entire uAssets, so I handled several edge cases. We will use ECSSTree in a static analyzer tool, which should parse all types of adblock rules, but I think it can be used for any other purpose as long as it helps working with Extended CSS language elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants