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

feat: to network modifier #4524

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

Conversation

seia-soto
Copy link
Member

@seia-soto seia-soto commented Dec 12, 2024

This partially implements https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#to.

In the documentation, to is described as:

to= is a superset of denyallow= with support for Entity-based syntax and also negated hostname.

However, we already support entity-based syntax in Domains and only thing required is negation according to entity documentation: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#entity

We still don't support regular expression both in domain and denyallow options. Same goes for to: *$to=~/regex.../.

  • denyallow with uBo: ✅ negation and listing ❌ entities ❌ regex
  • to with uBo: ✅ negation and listing ✅ entities ✅ regex
  • denyallow, to with Ghostery: ✅ negation and listing ✅ entities ❌ regex

This PR negates all hostnames in parse-time to flip the behavior of denyallow when to is detected.
Also, rejects to parse filter having both denyallow and to since both are not likely to be used together.
We can merge multiple domains then make it work but then we'll require extra space that allows us to determine which hostname is for to and denyallow when running toString.

This PR also fixes denyallow domain list not being printed in a correct format from toString method. There's a same regression in toString regrading other network modifiers utilizing Domains like from and planned to fix in separate PR.

! incorrect
||domain.tld$denyallow=a.com,b.com

! correct
||domain.tld$denyallow=a.com|b.com

@seia-soto seia-soto added the PR: New Feature 🚀 Increment minor 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 07:08
@seia-soto seia-soto changed the title feat: introduce $to in NetworkFilters feat: to network modifier Dec 12, 2024
@seia-soto
Copy link
Member Author

Despite we marked it's not safe to add one more bit before, but it's still safe to use 31st bit given that we're treating the number as unsigned integer.

> const buf = new Uint8Array(4)
undefined
> buf.length
4
> buf[0] = (1 << 31) >>> 24
128
> buf
Uint8Array(4) [ 128, 0, 0, 0 ]
> (buf[0] << 24) >>> 0
2147483648

@@ -153,6 +153,7 @@ export const enum NETWORK_FILTER_MASK {
isHostnameAnchor = 1 << 28,
isRedirectRule = 1 << 29,
isRedirect = 1 << 30,
isTo = 1 << 31,
Copy link
Member

Choose a reason for hiding this comment

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

why do we need the flag? looks like it is never read

it should not be needed if we convert $to to $denyallow

Copy link
Member Author

Choose a reason for hiding this comment

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

This is required to build an original form in toString

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is good enough reason to use the slot in the mask

context('to', () => {
it('fails when both denyallow and to used', () => {
network('||foo.com$denyallow=foo.com,to=bar.com', null);
network('||foo.com$to=foo.com,denyallow=bar.com', null);
Copy link
Member

Choose a reason for hiding this comment

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

if both present, can we merge them instead of dropping?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we can normalize them.

Copy link
Member

Choose a reason for hiding this comment

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

lets try to do that please

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in 35c36cc

@seia-soto seia-soto requested a review from chrmod December 13, 2024 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: New Feature 🚀 Increment minor version when merged WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants