[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [messagelib] webengineviewer/src/checkphishingurl: Create static method
From:       Montel Laurent <montel () kde ! org>
Date:       2016-12-09 7:13:50
Message-ID: E1cFFNO-00021V-Ar () code ! kde ! org
[Download RAW message or body]

Git commit da3f82492c4406fdc77e1ab3c76b8b7aef8b42ad by Montel Laurent.
Committed on 09/12/2016 at 07:07.
Pushed by mlaurent into branch 'master'.

Create static method

M  +11   -12   webengineviewer/src/checkphishingurl/autotests/urlhashingtest.cpp
M  +10   -10   webengineviewer/src/checkphishingurl/urlhashing.cpp
M  +3    -3    webengineviewer/src/checkphishingurl/urlhashing.h

https://commits.kde.org/messagelib/da3f82492c4406fdc77e1ab3c76b8b7aef8b42ad

diff --git a/webengineviewer/src/checkphishingurl/autotests/urlhashingtest.cpp \
b/webengineviewer/src/checkphishingurl/autotests/urlhashingtest.cpp index \
                1ccf2a38..63852362 100644
--- a/webengineviewer/src/checkphishingurl/autotests/urlhashingtest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/urlhashingtest.cpp
@@ -108,9 +108,17 @@ void UrlHashingTest::shouldCanonicalizeUrl_data()
     QTest::newRow("https://www.securesite.com/") << \
QStringLiteral("https://www.securesite.com/") << \
                QStringLiteral("https://www.securesite.com/");
     QTest::newRow("http://host.com/ab%23cd") << \
QStringLiteral("http://host.com/ab%23cd") << \
QStringLiteral("http://host.com/ab%23cd");  \
QTest::newRow("http://host.com//twoslashes?more//slashes") << \
QStringLiteral("http://host.com//twoslashes?more//slashes") << \
QStringLiteral("http://host.com/twoslashes?more//slashes"); +}
 
+void UrlHashingTest::shouldCanonicalizeUrl()
+{
+    QFETCH(QString, input);
+    QFETCH(QString, output);
+    input = input.trimmed();
+    QCOMPARE(WebEngineViewer::UrlHashing::canonicalizeUrl(QUrl::fromUserInput(input)), \
output);  }
 
+
 void UrlHashingTest::shouldGenerateHostPath_data()
 {
     QTest::addColumn<QString>("input");
@@ -139,20 +147,11 @@ void UrlHashingTest::shouldGenerateHostPath()
     QFETCH(QString, input);
     QFETCH(QStringList, hosts);
     QFETCH(QStringList, paths);
-    WebEngineViewer::UrlHashing handling(QUrl::fromUserInput(input));
-    QString result = handling.canonicalizeUrl();
+    QString result = \
WebEngineViewer::UrlHashing::canonicalizeUrl(QUrl::fromUserInput(input));  
-    QCOMPARE(handling.generateHostsToCheck(), hosts);
-    QCOMPARE(handling.generatePathsToCheck(), paths);
+    QCOMPARE(WebEngineViewer::UrlHashing::generateHostsToCheck(result), hosts);
+    QCOMPARE(WebEngineViewer::UrlHashing::generatePathsToCheck(result), paths);
 }
 
-void UrlHashingTest::shouldCanonicalizeUrl()
-{
-    QFETCH(QString, input);
-    QFETCH(QString, output);
-    input = input.trimmed();
-    WebEngineViewer::UrlHashing handling(QUrl::fromUserInput(input));
-    QCOMPARE(handling.canonicalizeUrl(), output);
-}
 
 QTEST_MAIN(UrlHashingTest)
diff --git a/webengineviewer/src/checkphishingurl/urlhashing.cpp \
b/webengineviewer/src/checkphishingurl/urlhashing.cpp index 5b172087..2cf70e0a 100644
--- a/webengineviewer/src/checkphishingurl/urlhashing.cpp
+++ b/webengineviewer/src/checkphishingurl/urlhashing.cpp
@@ -33,14 +33,14 @@ UrlHashing::~UrlHashing()
 
 }
 
-QString UrlHashing::canonicalizeUrl()
+QString UrlHashing::canonicalizeUrl(QUrl url)
 {
-    if (mUrl.isEmpty()) {
+    if (url.isEmpty()) {
         return {};
     }
-    QString path = mUrl.path();
-    if (mUrl.path().isEmpty()) {
-        mUrl.setPath(QStringLiteral("/"));
+    QString path = url.path();
+    if (url.path().isEmpty()) {
+        url.setPath(QStringLiteral("/"));
     } else {
         // First, remove tab (0x09), CR (0x0d), and LF (0x0a) characters from the \
URL. Do not remove escape sequences for these characters (e.g. '%0a').  \
path.remove(QLatin1Char('\t')); @@ -50,11 +50,11 @@ QString \
                UrlHashing::canonicalizeUrl()
         //In the URL, percent-escape all characters that are <= ASCII 32, >= 127, \
"#", or "%". The escapes should use uppercase hex characters.  //TODO
 
-        mUrl.setPath(path);
+        url.setPath(path);
     }
     // Remove all leading and trailing dots.
 #if 0
-    QString hostname = mUrl.host();
+    QString hostname = url.host();
     qDebug() << " hostname" << hostname;
     while (!hostname.isEmpty() && hostname.at(0) == QLatin1Char('.')) {
         hostname.remove(0, 1);
@@ -70,19 +70,19 @@ QString UrlHashing::canonicalizeUrl()
     qDebug() << "2222222 hostname" << hostname;
     mUrl.setHost(hostname);
 #endif
-    QByteArray urlEncoded = mUrl.toEncoded(QUrl::RemoveFragment | \
QUrl::NormalizePathSegments | QUrl::EncodeUnicode | QUrl::RemoveUserInfo | \
QUrl::RemovePort | QUrl::RemovePassword); +    QByteArray urlEncoded = \
url.toEncoded(QUrl::RemoveFragment | QUrl::NormalizePathSegments | \
QUrl::EncodeUnicode | QUrl::RemoveUserInfo | QUrl::RemovePort | \
QUrl::RemovePassword);  //qDebug() << "BEFORE  urlEncoded" <<urlEncoded;
     urlEncoded.replace(QByteArrayLiteral("%25"), QByteArrayLiteral("%"));
     //qDebug() << "AFTER  urlEncoded" <<urlEncoded;
     return QString::fromLatin1(urlEncoded);
 }
 
-QStringList UrlHashing::generatePathsToCheck()
+QStringList UrlHashing::generatePathsToCheck(const QString &str)
 {
     return {};
 }
 
-QStringList UrlHashing::generateHostsToCheck()
+QStringList UrlHashing::generateHostsToCheck(const QString &str)
 {
     return {};
 }
diff --git a/webengineviewer/src/checkphishingurl/urlhashing.h \
b/webengineviewer/src/checkphishingurl/urlhashing.h index b6893e9e..988c2564 100644
--- a/webengineviewer/src/checkphishingurl/urlhashing.h
+++ b/webengineviewer/src/checkphishingurl/urlhashing.h
@@ -33,9 +33,9 @@ public:
     UrlHashing(const QUrl &url);
     ~UrlHashing();
 
-    QString canonicalizeUrl();
-    QStringList generatePathsToCheck();
-    QStringList generateHostsToCheck();
+    static QString canonicalizeUrl(QUrl url);
+    static QStringList generatePathsToCheck(const QString &str);
+    static QStringList generateHostsToCheck(const QString &str);
 
     QByteArray hashComputation();
     QByteArray hashPrefixComputation();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic