AdguardTeam / ExtendedCss

A TypeScript library for non-standard element selecting — :contains(), :matches-css(), etc., and applying CSS styles with extended properties.
GNU General Public License v3.0
65 stars 9 forks source link

':xpath()' syntax unsupported or suppress errors while handling rules #144

Closed Birbber closed 2 years ago

Birbber commented 2 years ago

@seia-soto commented on Thu Mar 31 2022

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

Issue Details

Expected Behavior

AdGuard should run properly without any error and block ads on the website I am visiting.

Or even if the error occurred during the parsing process, AdGuard should execute remaining the proper rules regardless of the error status.

Actual Behavior

AdGuard crashed during its execution of extension content if there is :xpath syntax in the filter list.

Error: CssParser: parse error at position 317

error — extended-css.js:4623
parseCss — extended-css.js:4687
ExtendedCss — extended-css.js:5265
applyExtendedCss — script.js:131
applyAdvancedBlockingData — script.js:180
handleMessage — script.js:213

Screenshots

Screenshot: ![](https://user-images.githubusercontent.com/30369714/161116130-ced14448-bb8c-471f-83f6-1f32fea43179.png) ``` Error: CssParser: parse error at position 317 error — extended-css.js:4623 parseCss — extended-css.js:4687 ExtendedCss — extended-css.js:5265 applyExtendedCss — script.js:131 applyAdvancedBlockingData — script.js:180 handleMessage — script.js:213 ``` ![](https://user-images.githubusercontent.com/30369714/161117356-5de4f9fb-03ad-4e75-b4e2-2af4b5673532.png) ``` 0 "div:not([class]) > table + .wiki-paragraph:nth-ancestor(1)" 1 "div:not([class]):has(> table + .wiki-paragraph)" 2 "div:not([class]):has(> table + .wiki-paragraph)" 3 ":xpath(//article/h1/following-sibling::div[1]/following-sibling::div//div[count(*)>1][not(ancestor::div[count(*)>1]/ancestor::article)]/div[…" 4 ":xpath(//article/h1/following-sibling::div[1]/following-sibling::div//div[count(*)>1]//div[count(*)>1][not(ancestor::div[count(*)>1]/ancesto…" 5 "div:not([class]):has(> table + .wiki-paragraph)" 6 "#app > div[class]:matches-attr(\"/data-v-/\") > div > div:has(> a[href=\"https://namu.news\"])" 7 "aside > div[class]:matches-attr(\"/data-v-/\"):has(> a[href=\"https://namu.news\"])" ```

Additional Information

I know that we need more investigation about this but the problematic :xpath rule is working well on Chrome and Firefox with AdGuard browser extension installed.

If I apply following filters into AdGuard Safari Extension, I can see that ad is blocked properly without any error. Note that YousList includes :xpath rule first and I disabled manually.

namu.wiki#?#div:not([class]):has(> table + .wiki-paragraph)
namu.wiki#@#:xpath(//article/h1/following-sibling::div[1]/following-sibling::div//div[count(*)>1]//div[count(*)>1][not(ancestor::div[count(*)>1]/ancestor::div[count(*)>1]/ancestor::article)]/div[.//ul/li|.//a[contains(@href,'/w/%EB%B6%84%EB%A5%98:')]]/following-sibling::div[.//div[contains(concat(' ',normalize-space(@class),' '),' namuwiki-toc-ad ')]|.//div[contains(concat(' ',normalize-space(@class),' '),' wiki-paragraph ')]]/following-sibling::div[count(.//*[count(img[starts-with(@src,'//w.namu.la/s/')]|img[starts-with(@src,'//ww.namu.la/s/')]|img[starts-with(@src,'data:image/png;base64,')])>1])>1])
namu.wiki#@#:xpath(//article/h1/following-sibling::div[1]/following-sibling::div//div[count(*)>1][not(ancestor::div[count(*)>1]/ancestor::article)]/div[1])

Related

slavaleleka commented 2 years ago

will be fixed in ExtendedCss v2.0

we use Sizzle for parsing extended selectors and it fails with some xpath expressions. the issue is known and should be fixed after we ditch Sizzle