diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-15 11:56:04 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-21 20:14:56 +0300 |
commit | 761446e34af7a81d0516e322228616ebd046c9ba (patch) | |
tree | 6a232c099e061960be812a579b174d3ca5d50ea3 /staging/adblock/rule.h | |
parent | Add some FilterList tests (diff) | |
download | smolbote-761446e34af7a81d0516e322228616ebd046c9ba.tar.xz |
Fix MatcherRule with DomainMatch
Diffstat (limited to 'staging/adblock/rule.h')
-rw-r--r-- | staging/adblock/rule.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/staging/adblock/rule.h b/staging/adblock/rule.h index 90062ba..0dbff21 100644 --- a/staging/adblock/rule.h +++ b/staging/adblock/rule.h @@ -39,10 +39,19 @@ protected: const Options options; }; +// The separator character can be anything but +// a letter, a digit, or one of the following: _, -, ., %. +// The end of the address is also accepted as a separator. +inline bool isSeparator(const QChar &c) +{ + return !c.isLetter() && !c.isDigit() && c != '_' && c != '-' && c != '.' && c != '%'; +} + class MatcherRule : public Rule { public: enum MatchPosition { + DomainMatch, UrlStartsWith, UrlEndsWith, UrlContains, @@ -66,8 +75,17 @@ public: bool hasMatch(const QStringRef &url) const override { const auto index = matcher.indexIn(url); + if(index == -1) { + return false; + } switch(position) { + case DomainMatch: + // match if + // there is only one : left of the index + // and + // character after pattern is separator or end of string + return (url.left(index).count(':') <= 1 && (index + patternLength == url.length() || isSeparator(url[index + patternLength]))); case UrlStartsWith: return (index == 0); case UrlEndsWith: @@ -77,6 +95,8 @@ public: case UrlEquals: return (index == 0 && patternLength == url.length()); } + + return false; } private: |