From 29f584fb51738385b4257d35d4041bac6e72071d Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 19 Apr 2020 18:45:20 +0300 Subject: Fix some clazy warnings --- meson.build | 2 +- staging/adblock/rule.h | 14 ++++++------- staging/adblock/test/filterlist.cpp | 42 +++++++++++++++++++++++-------------- staging/adblock/test/rule.cpp | 32 +++++++++++++++------------- staging/smolblok/filtermanager.hpp | 2 +- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/meson.build b/meson.build index ef479a4..a34b551 100644 --- a/meson.build +++ b/meson.build @@ -101,7 +101,7 @@ poi_exe = executable(get_option('poi'), cpp_args: ['-DQAPPLICATION_CLASS=QApplication', poi_cpp_args], sources: [ssconfig.sources()], include_directories: [include, include_directories('src')], - dependencies: [ dep_qt5, dep_spdlog, dep_SingleApplication, dep_args, optional_deps, dep_bookmarks, dep_configuration, dep_downloads, dep_pluginloader, dep_urlfilter, dep_plugininterface, ssconfig.dependencies(), lib_session_formats ], + dependencies: [ dep_qt5, dep_spdlog, dep_SingleApplication, dep_args, optional_deps, dep_bookmarks, dep_configuration, dep_downloads, dep_pluginloader, dep_urlfilter, ssconfig.dependencies(), lib_session_formats ], install: true, ) diff --git a/staging/adblock/rule.h b/staging/adblock/rule.h index 26a8249..aaab49a 100644 --- a/staging/adblock/rule.h +++ b/staging/adblock/rule.h @@ -17,8 +17,6 @@ namespace AdblockPlus { -static const QString defaultUrl; - class Rule { public: @@ -29,8 +27,8 @@ public: * firstPartyUrl: URL of the page that issued the request */ virtual bool hasMatch(const QStringRef &requestUrl, - const QStringRef &initiatorUrl = QStringRef(&defaultUrl), - const QStringRef &firstPartyUrl = QStringRef(&defaultUrl), + const QStringRef &initiatorUrl, + const QStringRef &firstPartyUrl, QWebEngineUrlRequestInfo::ResourceType resourceType = QWebEngineUrlRequestInfo::ResourceTypeMainFrame) const = 0; bool shouldRedirect() const @@ -84,8 +82,8 @@ public: ~MatcherRule() = default; bool hasMatch(const QStringRef &url, - const QStringRef &initiatorUrl = QStringRef(&defaultUrl), - const QStringRef &firstPartyUrl = QStringRef(&defaultUrl), + const QStringRef &initiatorUrl, + const QStringRef &firstPartyUrl, QWebEngineUrlRequestInfo::ResourceType resourceType = QWebEngineUrlRequestInfo::ResourceTypeMainFrame) const override { const auto index = matcher.indexIn(url); @@ -138,8 +136,8 @@ public: ~RegexRule() = default; bool hasMatch(const QStringRef &url, - const QStringRef &initiatorUrl = QStringRef(&defaultUrl), - const QStringRef &firstPartyUrl = QStringRef(&defaultUrl), + const QStringRef &initiatorUrl, + const QStringRef &firstPartyUrl, QWebEngineUrlRequestInfo::ResourceType resourceType = QWebEngineUrlRequestInfo::ResourceTypeMainFrame) const override { const auto match = regex.match(url); diff --git a/staging/adblock/test/filterlist.cpp b/staging/adblock/test/filterlist.cpp index 262e84b..ca122ac 100644 --- a/staging/adblock/test/filterlist.cpp +++ b/staging/adblock/test/filterlist.cpp @@ -22,6 +22,8 @@ TEST_CASE("placeholder") TEST_CASE("domain match") { + const QString defaultUrl = ""; + const QString block1 = "http://ads.example.com/foo.gif"; const QString block2 = "http://server1.ads.example.com/foo.gif"; const QString block3 = "https://ads.example.com:8000/"; @@ -34,19 +36,21 @@ TEST_CASE("domain match") REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); - REQUIRE(rule->hasMatch(&block1)); - REQUIRE(rule->hasMatch(&block2)); - REQUIRE(rule->hasMatch(&block3)); - REQUIRE(rule->hasMatch(&block4)); + REQUIRE(rule->hasMatch(&block1, &defaultUrl, &defaultUrl)); + REQUIRE(rule->hasMatch(&block2, &defaultUrl, &defaultUrl)); + REQUIRE(rule->hasMatch(&block3, &defaultUrl, &defaultUrl)); + REQUIRE(rule->hasMatch(&block4, &defaultUrl, &defaultUrl)); - REQUIRE(!rule->hasMatch(&allow1)); - REQUIRE(!rule->hasMatch(&allow2)); + REQUIRE(!rule->hasMatch(&allow1, &defaultUrl, &defaultUrl)); + REQUIRE(!rule->hasMatch(&allow2, &defaultUrl, &defaultUrl)); delete rule; } TEST_CASE("string equals") { + const QString defaultUrl = ""; + const QString block = "http://example.com/"; const QString allow1 = "http://example.com/foo.gif"; @@ -56,16 +60,18 @@ TEST_CASE("string equals") REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); - REQUIRE(rule->hasMatch(&block)); + REQUIRE(rule->hasMatch(&block, &defaultUrl, &defaultUrl)); - REQUIRE(!rule->hasMatch(&allow1)); - REQUIRE(!rule->hasMatch(&allow2)); + REQUIRE(!rule->hasMatch(&allow1, &defaultUrl, &defaultUrl)); + REQUIRE(!rule->hasMatch(&allow2, &defaultUrl, &defaultUrl)); delete rule; } TEST_CASE("string starts with") { + const QString defaultUrl = ""; + auto *rule = FilterList::parseRule("|http://baddomain.example/"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); @@ -73,13 +79,15 @@ TEST_CASE("string starts with") const QString blocks = "http://baddomain.example/banner.gif"; const QString allows = "http://gooddomain.example/analyze?http://baddomain.example"; - REQUIRE(rule->hasMatch(&blocks)); - REQUIRE(!rule->hasMatch(&allows)); + REQUIRE(rule->hasMatch(&blocks, &defaultUrl, &defaultUrl)); + REQUIRE(!rule->hasMatch(&allows, &defaultUrl, &defaultUrl)); delete rule; } TEST_CASE("string ends with") { + const QString defaultUrl = ""; + auto *rule = FilterList::parseRule("swf|"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); @@ -87,22 +95,24 @@ TEST_CASE("string ends with") const QString blocks = "http://example.com/annoyingflash.swf"; const QString allows = "http://example.com/swf/index.html"; - REQUIRE(rule->hasMatch(&blocks)); - REQUIRE(!rule->hasMatch(&allows)); + REQUIRE(rule->hasMatch(&blocks, &defaultUrl, &defaultUrl)); + REQUIRE(!rule->hasMatch(&allows, &defaultUrl, &defaultUrl)); delete rule; } TEST_CASE("regular expressions") { + const QString defaultUrl = ""; + 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)); + REQUIRE(rule->hasMatch(&matches1, &defaultUrl, &defaultUrl)); + REQUIRE(rule->hasMatch(&matches2, &defaultUrl, &defaultUrl)); + REQUIRE(!rule->hasMatch(&ignores, &defaultUrl, &defaultUrl)); delete rule; } diff --git a/staging/adblock/test/rule.cpp b/staging/adblock/test/rule.cpp index 31af7d5..07186b9 100644 --- a/staging/adblock/test/rule.cpp +++ b/staging/adblock/test/rule.cpp @@ -8,6 +8,8 @@ SCENARIO("MatcherRule") { GIVEN("options with case sensitive pattern") { + const QString defaultUrl = ""; + const Options opt { .matchcase=true }; const QString patternContains("this string contains the pattern in it"); const QString patternBegins("pattern starts this string"); @@ -21,10 +23,10 @@ SCENARIO("MatcherRule") THEN("pattern is matched anywhere in the URL") { - REQUIRE(rule.hasMatch(&patternContains)); - REQUIRE(rule.hasMatch(&patternBegins)); - REQUIRE(rule.hasMatch(&patternEnds)); - REQUIRE(!rule.hasMatch(&patternMissing)); + REQUIRE(rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl)); + REQUIRE(rule.hasMatch(&patternBegins, &defaultUrl, &defaultUrl)); + REQUIRE(rule.hasMatch(&patternEnds, &defaultUrl, &defaultUrl)); + REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl)); } } @@ -35,10 +37,10 @@ SCENARIO("MatcherRule") THEN("pattern is matched if at the start of the URL") { - REQUIRE(!rule.hasMatch(&patternContains)); - REQUIRE(rule.hasMatch(&patternBegins)); - REQUIRE(!rule.hasMatch(&patternEnds)); - REQUIRE(!rule.hasMatch(&patternMissing)); + REQUIRE(!rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl)); + REQUIRE(rule.hasMatch(&patternBegins, &defaultUrl, &defaultUrl)); + REQUIRE(!rule.hasMatch(&patternEnds, &defaultUrl, &defaultUrl)); + REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl)); } } @@ -49,10 +51,10 @@ SCENARIO("MatcherRule") THEN("pattern is matched if at the end of the URL") { - REQUIRE(!rule.hasMatch(&patternContains)); - REQUIRE(!rule.hasMatch(&patternBegins)); - REQUIRE(rule.hasMatch(&patternEnds)); - REQUIRE(!rule.hasMatch(&patternMissing)); + REQUIRE(!rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl)); + REQUIRE(!rule.hasMatch(&patternBegins, &defaultUrl, &defaultUrl)); + REQUIRE(rule.hasMatch(&patternEnds, &defaultUrl, &defaultUrl)); + REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl)); } } } @@ -62,6 +64,8 @@ SCENARIO("RegexRule") { GIVEN("options with case sensitive pattern") { + const QString defaultUrl; + const Options opt { .matchcase=true }; const QString patternContains("this string contains the pattern in it"); const QString patternMissing("and this one does not"); @@ -73,8 +77,8 @@ SCENARIO("RegexRule") THEN("pattern is matched anywhere in the URL") { - REQUIRE(rule.hasMatch(&patternContains)); - REQUIRE(!rule.hasMatch(&patternMissing)); + REQUIRE(rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl)); + REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl)); } } } diff --git a/staging/smolblok/filtermanager.hpp b/staging/smolblok/filtermanager.hpp index 2003d76..2620bd8 100644 --- a/staging/smolblok/filtermanager.hpp +++ b/staging/smolblok/filtermanager.hpp @@ -40,7 +40,7 @@ public: void interceptRequest(QWebEngineUrlRequestInfo &info) override { - for(const auto *filter : filters) { + for(const auto *filter : qAsConst(filters)) { if(filter->filter(info)) { return; } -- cgit v1.2.1