SafariConverterLib icon indicating copy to clipboard operation
SafariConverterLib copied to clipboard

Subdomain match should use `*` to match multiple level of the subdomains

Open mingchen opened this issue 3 years ago • 3 comments

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.

mingchen avatar Nov 14 '22 20:11 mingchen

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.

ameshkov avatar Nov 15 '22 07:11 ameshkov

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?

mingchen avatar Nov 16 '22 05:11 mingchen

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

No particular reason, I guess these are interchangeable anyways.

ameshkov avatar Nov 16 '22 16:11 ameshkov