[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/khtml
From: Maks Orlovich <maksim () kde ! org>
Date: 2010-10-30 20:26:09
Message-ID: 20101030202609.0F439AC89B () svn ! kde ! org
[Download RAW message or body]
SVN commit 1191378 by orlovich:
- Better escaping in wildcard mode
- Be consistent in excluding stuff we don't handle.
M +34 -19 khtml_filter.cpp
M +1 -4 khtml_settings.cpp
--- trunk/KDE/kdelibs/khtml/khtml_filter.cpp #1191377:1191378
@@ -31,11 +31,39 @@
namespace khtml {
+// We only want a subset of features of wildcards -- just the
+// star, so we escape the rest before passing to QRegExp.
+// The \ is escaped due to a QRegExp bug.
+// ### we really should rather parse it ourselves, in order to
+// handle adblock-special things like | and ^ properly.
+static QRegExp fromAdBlockWildcard(const QString& wcStr) {
+ QRegExp rx;
+ rx.setPatternSyntax(QRegExp::Wildcard);
+
+ QString out;
+ for (int p = 0; p < wcStr.length(); ++p) {
+ QChar c = wcStr[p];
+ if (c == QLatin1Char('?'))
+ out += QLatin1String("[?]");
+ else if (c == QLatin1Char('['))
+ out += QLatin1String("[[]");
+ else if (c == QLatin1Char('\\'))
+ out += QLatin1String("[\\]");
+ else
+ out += c;
+ }
+
+ rx.setPattern(out);
+ return rx;
+}
+
void FilterSet::addFilter(const QString& filterStr)
{
QString filter = filterStr;
- if (filter.startsWith(QLatin1Char('!')))
+ /** ignore special lines starting with "[", "!", "&", or "#" or contain "#" \
(comments or features are not supported by KHTML's AdBlock */ + QChar firstChar = \
filter.at(0); + if (firstChar == QLatin1Char('[') || firstChar == QLatin1Char('!') \
|| firstChar == QLatin1Char('&') || firstChar == QLatin1Char('#') || \
filter.contains(QLatin1Char('#'))) return;
// Strip leading @@
@@ -86,29 +114,16 @@
// Now, do we still have any wildcard stuff left?
if (filter.contains("*"))
{
-// qDebug() << "W:" << filter;
// check if we can use RK first (and then check full RE for the rest) \
for better performance int aPos = filter.indexOf('*');
if (aPos < 0)
aPos = filter.length();
- int qPos = filter.indexOf('?');
- if (qPos < 0)
- qPos = filter.length();
- int pos = qMin(aPos, qPos);
- if (pos > 7) {
- QRegExp rx;
-
- rx.setPatternSyntax(QRegExp::Wildcard);
- // Pad the final r.e. with * so we can check for an exact match
- rx.setPattern(filter.mid(pos) + QLatin1Char('*'));
-
- stringFiltersMatcher.addWildedString(filter.mid(0, pos), rx);
-
+ if (aPos > 7) {
+ QRegExp rx = fromAdBlockWildcard(filter.mid(aPos) + \
QLatin1Char('*')); + // We pad the final r.e. with * so we can check \
for an exact match + \
stringFiltersMatcher.addWildedString(filter.mid(0, aPos), rx); } else {
- QRegExp rx;
-
- rx.setPatternSyntax(QRegExp::Wildcard);
- rx.setPattern(filter);
+ QRegExp rx = fromAdBlockWildcard(filter);
reFilters.append(rx);
}
}
--- trunk/KDE/kdelibs/khtml/khtml_settings.cpp #1191377:1191378
@@ -138,7 +138,6 @@
int whiteCounter = 0, blackCounter = 0;
#endif // NDEBUG
while (!line.isEmpty()) {
- QChar firstChar = line.at(0);
/** white list lines start with "@@" */
if (line.startsWith(QLatin1String("@@")))
{
@@ -147,9 +146,7 @@
#endif // NDEBUG
adWhiteList.addFilter(line);
}
- /** ignore special lines starting with "[", "!", "&", or "#" or \
contain "#"
- (those features are not supported by KHTML's AdBlock */
- else if (firstChar != QLatin1Char('[') && firstChar != \
QLatin1Char('!') && firstChar != QLatin1Char('&') && firstChar != QLatin1Char('#') && \
!line.contains(QLatin1Char('#'))) + else
{
#ifndef NDEBUG
++blackCounter;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic