aboutsummaryrefslogtreecommitdiff
path: root/staging/adblock/rule.h
diff options
context:
space:
mode:
Diffstat (limited to 'staging/adblock/rule.h')
-rw-r--r--staging/adblock/rule.h20
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: