Web lists-archives.com

[PATCH 1/2] Fix URL parsing




From: Arno <arno@xxxxxxxxxxxxx>

As it seems, QUrl does not know about rdp://, so url.scheme() is empty.
The old code tried to "fix" it by replacing the scheme with vnc://,
because, as the comment stated, it was default in kde3.

Fix the "fix" by explicitly looking for supported schemes (vnc://, rdp://
and nx://, are there more?).
---
 main.cpp | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/main.cpp b/main.cpp
index 73093f3..e5374c4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -122,17 +122,11 @@ int main(int argc, char **argv)
             if (url.scheme().isEmpty() || url.host().isEmpty()) { // unusable url; try to recover it...
                 QString arg = args.at(i);
 
-                qCDebug(KRDC) << "unusable url; try to recover it:" << arg;
-
-                if (arg.lastIndexOf(QLatin1Char('/')) != 0)
-                    arg = arg.right(arg.length() - arg.lastIndexOf(QLatin1Char('/')) - 1);
-
-                if (!arg.contains(QStringLiteral("://")))
-                    arg.prepend(QStringLiteral("vnc://")); // vnc was default in kde3 times...
-
-                qCDebug(KRDC) << "recovered url:" << arg;
-
-                url = QUrl(arg);
+                if(arg.startsWith(QStringLiteral("rdp://")) || arg.startsWith(QStringLiteral("vnc://")) || arg.startsWith(QStringLiteral("nx://"))){
+                    url = QUrl(arg);
+                }else{
+                    qCDebug(KRDC) << "skipped url:" << arg << "because it's invalid";
+                }
             }
             if (!url.isValid()) {
                 continue;
-- 
2.8.2