mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
AdBlock: Add support for rules with empty filter (match all)
This commit is contained in:
parent
67c6834a5f
commit
c2c49c6b13
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
||||
* QupZilla - Qt web browser
|
||||
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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<QStringMatcher> 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
||||
* QupZilla - Qt web browser
|
||||
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user