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

fix: check domains validity when parsing network filters #4525

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

seia-soto
Copy link
Member

From #4524, I found that NetworkFilter.prototype.toString is broken for network modifiers utilizing Domains.

This fixes it by replacing all , into | in Domains.parts.

Also, this moves invalid option value check which was used to prevent passing $domain=|a.com| forms into Domains.prototype.parse.

@seia-soto seia-soto added the PR: Bug Fix 🐛 Increment patch version when merged label Dec 12, 2024
@seia-soto seia-soto self-assigned this Dec 12, 2024
@seia-soto seia-soto requested a review from remusao as a code owner December 12, 2024 08:07
Copy link
Member

@chrmod chrmod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some tests for those changes?

@seia-soto
Copy link
Member Author

@chrmod Added 96f51b8 (#4525)

@seia-soto seia-soto requested a review from chrmod December 13, 2024 06:35
packages/adblocker/test/parsing.test.ts Outdated Show resolved Hide resolved
packages/adblocker/test/parsing.test.ts Outdated Show resolved Hide resolved
@seia-soto seia-soto requested a review from chrmod December 25, 2024 04:53
@seia-soto
Copy link
Member Author

@chrmod I realized that it was improper to add a check in the Domains.prototype.parse since it was also used by cosmetics. Instead, I created a separate function called #normalizeNetworkEntities to do this. Also, new change includes:

  • Tests for #normalizeNetworkEntities and NetworkFilter.prototype.toString

@seia-soto
Copy link
Member Author

Tests are currently expected to fail: see #4525 (comment)

@seia-soto seia-soto marked this pull request as draft December 30, 2024 05:54
@seia-soto seia-soto changed the title refactor: integrate emptiness check to Domains.prototype.parse fix: check domains validity when parsing network filters Dec 31, 2024
@seia-soto seia-soto marked this pull request as ready for review December 31, 2024 10:38
@seia-soto
Copy link
Member Author

One more idea to this would be having a Domains.prototype.toString method and accept isNetworkFilter = false as a first argument.

packages/adblocker/src/engine/domains.ts Outdated Show resolved Hide resolved
packages/adblocker/src/engine/domains.ts Outdated Show resolved Hide resolved
Copy link
Member

@chrmod chrmod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to move the splitting to Domain.parse and pass a desired separator as an argument?

The logic for the trailing | may apply to trailing ,.

Or alternatively, we could ignore those trailing characters as filters that include them (if they exist) may still be useful. The question is how fault tolerant we want to be. Eg. Should we drop filter: test$domain=example.com|example.org||

@seia-soto
Copy link
Member Author

@chrmod I believe adblocker should not be error tolerant here.

  • We had a test that reject those typos
  • Those typo happens only if a filter maintainer is developing a filter

For the dynamic delimiter, I agree that we can just accept the string instead of boolean flag.

packages/adblocker/src/engine/domains.ts Outdated Show resolved Hide resolved
@seia-soto seia-soto requested review from chrmod and remusao January 16, 2025 08:29
seia-soto and others added 2 commits January 16, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Bug Fix 🐛 Increment patch version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants