aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-04-15 13:03:49 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-04-21 20:14:56 +0300
commitf8e421c638efe04a5de36a730c97f05325140ee0 (patch)
tree35bf9968032bacb54dd8f011f3c9c58d82379789
parentFix MatcherRule with DomainMatch (diff)
downloadsmolbote-f8e421c638efe04a5de36a730c97f05325140ee0.tar.xz
Add tests for regex rules
-rw-r--r--staging/adblock/filterlist.cpp11
-rw-r--r--staging/adblock/test/filterlist.cpp15
2 files changed, 23 insertions, 3 deletions
diff --git a/staging/adblock/filterlist.cpp b/staging/adblock/filterlist.cpp
index d3f6134..5566c87 100644
--- a/staging/adblock/filterlist.cpp
+++ b/staging/adblock/filterlist.cpp
@@ -111,9 +111,14 @@ Rule *FilterList::parseRule(const QByteArray &line)
return new RegexRule(pattern, opt);
} else if(!pattern.isEmpty()) {
- // wildcard pattern
- pattern = QRegularExpression::wildcardToRegularExpression(pattern);
- return new RegexRule(pattern, opt);
+ if(pattern.contains('*')) {
+ // wildcard pattern
+ pattern = QRegularExpression::wildcardToRegularExpression(pattern);
+ return new RegexRule(pattern, opt);
+ } else {
+ // contains pattern
+ return new MatcherRule(pattern, opt);
+ }
}
return nullptr;
diff --git a/staging/adblock/test/filterlist.cpp b/staging/adblock/test/filterlist.cpp
index 4366489..262e84b 100644
--- a/staging/adblock/test/filterlist.cpp
+++ b/staging/adblock/test/filterlist.cpp
@@ -91,3 +91,18 @@ TEST_CASE("string ends with")
REQUIRE(!rule->hasMatch(&allows));
delete rule;
}
+
+TEST_CASE("regular expressions")
+{
+ auto *rule = FilterList::parseRule("/banner\\d+/");
+ const QString matches1 = "banner123";
+ const QString matches2 = "banner321";
+
+ const QString ignores = "banners";
+
+ REQUIRE(rule->hasMatch(&matches1));
+ REQUIRE(rule->hasMatch(&matches2));
+ REQUIRE(!rule->hasMatch(&ignores));
+ delete rule;
+}
+