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

Subdomain match should use * to match multiple level of the subdomains #46

Open
mingchen opened this issue Nov 14, 2022 · 3 comments
Open
Assignees

Comments

@mingchen
Copy link

Test Rule:

||example.com/foo/bar|

Generated rule:

 {
    "trigger": {
      "url-filter": "^[htpsw]+:\\/\\/([a-z0-9-]+\\.)?example\\.com\\/foo\\/bar$"
    },
    "action": {
      "type": "block"
    }
  }

There are two issues on this generated rule:

  1. There sub domain may have one than one depth. e.g. foo.example.com, foo.bar.example.com or foo.bar.foobar.example.com. So the match rule in url-filter should replace ? with * like "^[htpsw]+:\/\/([a-z0-9-]+\.)*example\.com\/foo\/bar$"
  2. Use \\/ to escape / is not necessary. You may just use /. e.g. "^[htpsw]+://([a-z0-9-]+\.)*example\.com/foo/bar$"

Regarding sub domain match, maybe refer to https://webkit.org/blog/4062/targeting-domains-with-content-blockers/ to write it in more effect way, e.g.

    "url-filter": "^[^:]+://+([^:/]+\.)*domain-to-match\.tld[:/]",

Note: use * instead of ? here to match multiple level of subdomains.

@ameshkov
Copy link
Member

We can experiment with this once again since the current rules were made a few years ago. However, the current regular expressions were chosen for a reason. Testing showed that there's a significant difference in compile time and the overall performance when we use a more narrow regex.

@mingchen
Copy link
Author

Thanks for info about performance testing.

  1. The main issue for this ticket is want to match subdomains with more than one depth. so maybe first step is use *to replace ? to solve the issue, then can run some performance testing to evaluate what is more effective regex.
  2. Is there any reason use \\/ instead of / in url-filter?

@ameshkov
Copy link
Member

Is there any reason use \/ instead of / in url-filter?

No particular reason, I guess these are interchangeable anyways.

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

No branches or pull requests

5 participants