Subdomain match should use `*` to match multiple level of the subdomains
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:
- There sub domain may have one than one depth. e.g.
foo.example.com,foo.bar.example.comorfoo.bar.foobar.example.com. So the match rule inurl-filtershould replace?with*like "^[htpsw]+:\/\/([a-z0-9-]+\.)*example\.com\/foo\/bar$" - 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.
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.
Thanks for info about performance testing.
- 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. - Is there any reason use
\\/instead of/inurl-filter?
Is there any reason use \/ instead of / in url-filter?
No particular reason, I guess these are interchangeable anyways.