diff --git a/src/lib/adblock/adblockrule.cpp b/src/lib/adblock/adblockrule.cpp index 163500f93..a0d654ca0 100644 --- a/src/lib/adblock/adblockrule.cpp +++ b/src/lib/adblock/adblockrule.cpp @@ -1,6 +1,6 @@ /* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* QupZilla - Qt web browser +* Copyright (C) 2010-2017 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -201,7 +201,6 @@ bool AdBlockRule::urlMatch(const QUrl &url) const return false; } - const QString encodedUrl = url.toEncoded(); const QString domain = url.host(); @@ -538,6 +537,18 @@ void AdBlockRule::parseFilter() return; } + // This rule matches all urls + if (parsedLine.isEmpty()) { + if (m_options == NoOption) { + qWarning() << "Disabling unrestricted rule that would block all requests" << m_filter; + m_isInternalDisabled = true; + m_type = Invalid; + return; + } + m_type = MatchAllUrlsRule; + return; + } + // We haven't found anything that needs use of regexp, yay! m_type = StringContainsMatchRule; m_matchString = parsedLine; @@ -671,23 +682,28 @@ QList AdBlockRule::createStringMatchers(const QStringList &filte bool AdBlockRule::stringMatch(const QString &domain, const QString &encodedUrl) const { - if (m_type == StringContainsMatchRule) { + switch (m_type) { + case StringContainsMatchRule: return encodedUrl.contains(m_matchString, m_caseSensitivity); - } - else if (m_type == DomainMatchRule) { + + case DomainMatchRule: return isMatchingDomain(domain, m_matchString); - } - else if (m_type == StringEndsMatchRule) { + + case StringEndsMatchRule: return encodedUrl.endsWith(m_matchString, m_caseSensitivity); - } - else if (m_type == RegExpMatchRule) { + + case RegExpMatchRule: if (!isMatchingRegExpStrings(encodedUrl)) { return false; } return (m_regExp->regExp.indexIn(encodedUrl) != -1); - } - return false; + case MatchAllUrlsRule: + return true; + + default: + return false; + } } bool AdBlockRule::isMatchingDomain(const QString &domain, const QString &filter) const diff --git a/src/lib/adblock/adblockrule.h b/src/lib/adblock/adblockrule.h index 84be0814a..342ed017a 100644 --- a/src/lib/adblock/adblockrule.h +++ b/src/lib/adblock/adblockrule.h @@ -1,6 +1,6 @@ /* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* QupZilla - Qt web browser +* Copyright (C) 2010-2017 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -116,10 +116,12 @@ private: RegExpMatchRule = 2, StringEndsMatchRule = 3, StringContainsMatchRule = 4, - Invalid = 5 + MatchAllUrlsRule = 5, + Invalid = 6 }; enum RuleOption { + NoOption = 0, DomainRestrictedOption = 1, ThirdPartyOption = 2, ObjectOption = 4, diff --git a/src/lib/adblock/adblocksearchtree.cpp b/src/lib/adblock/adblocksearchtree.cpp index de6317292..398400b23 100644 --- a/src/lib/adblock/adblocksearchtree.cpp +++ b/src/lib/adblock/adblocksearchtree.cpp @@ -46,7 +46,7 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule) int len = filter.size(); if (len <= 0) { - qDebug() << "AdBlockSearchTree: Inserting rule with filter len <= 0!"; + qDebug() << "AdBlockSearchTree: Inserting rule with filter len <= 0!" << rule->filter(); return false; }