Closed david-caroli closed 6 years ago
Thanks for the report! Not sure what I was thinking writing it this way.
There were other problems with this, so I've written a fix that addresses all of the issues. I've also added unit-tests for this, so this won't happen in the future. Please have a look at the above commit if you want to double check if there is anything I missed.
@Lusito The code looks good to me. Thank you for the quick fix and response!
The Problem:
In the screen-shot are 3 examples of rules that the domain
www.reddit.com
matches, even though it shouldn't:*.t.co
(wrong top level domain.co
and wrong domaint
)www.reddit.co
(wrong top level domain.co
)*.r.ddit.com
(r.ddit
should not matchreddit
)The likely cause:
The cause of this seems to be the conversion of the rule strings to regular expressions.
The culprit function seems to be
getRegExForRule(rule: string)
in settings.ts.getRegExForRule(rule: string)
correctly matches the start of the string using a^
, but it should do the same for the end of the string. (line 107 and line 110)Additionally the function doesn't escape the characters from the rule when adding them to the regular expression. This leads to the dots in the rule not being escaped and treated as a special character. (line 116 and line 117)
Possibly a solution:
I have never used TypeScript and I don't use JavaScript often so take the following with a grain of salt.
Change line 117 from
reParts.push(".");
toreParts.push("\\.");
.Before the return at line 121 add a line with
reParts.push("$");
.(see also RegEx Special Chars)
---
I hope the problem is reproducible and can be fixed. Thanks in advance!