1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Fixed small bug with domain matching

- accounts.youtube.com won't be matched by s.youtube.com anymore
- fixes ||s.youtube.com^ AdBlock rule matching anything from
  https://accounts.youtube.com
This commit is contained in:
nowrep 2012-09-01 11:41:12 +02:00
parent 575b211997
commit b442492c27
3 changed files with 40 additions and 8 deletions

View File

@ -204,7 +204,7 @@ bool AdBlockRule::networkMatch(const QNetworkRequest &request, const QString &do
bool matched = false;
if (m_useDomainMatch) {
matched = domain.endsWith(m_matchString);
matched = _matchDomain(domain, m_matchString);
}
else if (m_useEndsMatch) {
matched = encodedUrl.endsWith(m_matchString, m_caseSensitivity);
@ -270,14 +270,14 @@ bool AdBlockRule::matchDomain(const QString &domain) const
if (m_blockedDomains.isEmpty()) {
foreach(const QString & d, m_allowedDomains) {
if (domain.endsWith(d)) {
if (_matchDomain(domain, d)) {
return true;
}
}
}
else if (m_allowedDomains.isEmpty()) {
foreach(const QString & d, m_blockedDomains) {
if (domain.endsWith(d)) {
if (_matchDomain(domain, d)) {
return false;
}
}
@ -285,13 +285,13 @@ bool AdBlockRule::matchDomain(const QString &domain) const
}
else {
foreach(const QString & d, m_blockedDomains) {
if (domain.endsWith(d)) {
if (_matchDomain(domain, d)) {
return false;
}
}
foreach(const QString & d, m_allowedDomains) {
if (domain.endsWith(d)) {
if (_matchDomain(domain, d)) {
return true;
}
}
@ -520,3 +520,18 @@ void AdBlockRule::parseDomains(const QString &domains, const QChar &separator)
m_domainRestricted = (!m_blockedDomains.isEmpty() || !m_allowedDomains.isEmpty());
}
bool AdBlockRule::_matchDomain(const QString &domain, const QString &filter) const
{
if (!domain.endsWith(filter)) {
return false;
}
int index = domain.indexOf(filter);
if (index == 0 || filter[0] == '.') {
return true;
}
return domain[index - 1] == '.';
}

View File

@ -97,6 +97,8 @@ private:
void parseFilter();
void parseDomains(const QString &domains, const QChar &separator);
bool _matchDomain(const QString &domain, const QString &filter) const;
AdBlockSubscription* m_subscription;
QString m_filter;

View File

@ -25,7 +25,22 @@
//#define COOKIE_DEBUG
bool containsDomain(QString string, QString domain)
bool _matchDomain(const QString &domain, const QString &filter)
{
if (!domain.endsWith(filter)) {
return false;
}
int index = domain.indexOf(filter);
if (index == 0 || filter[0] == '.') {
return true;
}
return domain[index - 1] == '.';
}
bool containsDomain(QString string, const QString &domain)
{
if (string.isEmpty()) {
// Some cookies have empty domain() ... bug?
@ -36,7 +51,7 @@ bool containsDomain(QString string, QString domain)
string = string.mid(1);
}
return domain.endsWith(string);
return _matchDomain(domain, string);
}
int listContainsDomain(const QStringList &list, const QString &domain)
@ -46,7 +61,7 @@ int listContainsDomain(const QStringList &list, const QString &domain)
}
foreach(const QString & d, list) {
if (domain.endsWith(d)) {
if (_matchDomain(domain, d)) {
return 1;
}
}