From d02cd42d0e3c16daf4dd59940596df2d6860e01b Mon Sep 17 00:00:00 2001
From: Akira Ohgaki <akiraohgaki@gmail.com>
Date: Tue, 11 Oct 2016 11:45:33 +0900
Subject: [PATCH] XDG-URL validation

---
 src/handlers/xdgurl.cpp | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/src/handlers/xdgurl.cpp b/src/handlers/xdgurl.cpp
index e129740..d94acc5 100644
--- a/src/handlers/xdgurl.cpp
+++ b/src/handlers/xdgurl.cpp
@@ -275,29 +275,21 @@ QString XdgUrl::getMetadata()
 
 bool XdgUrl::isValid()
 {
-    bool isValid = true;
-
-    if (_metadata["scheme"].toString() != "xdg" && _metadata["scheme"].toString() != "xdgs") {
-        isValid = false;
-    }
-
-    if (_metadata["command"].toString() != "download" && _metadata["command"].toString() != "install") {
-        isValid = false;
-    }
-
-    if (!QUrl(_metadata["url"].toString()).isValid()) {
-        isValid = false;
-    }
-
-    if (!_destinations.contains(_metadata["type"].toString())) {
-        isValid = false;
-    }
+    QString scheme = _metadata["scheme"].toString();
+    QString command = _metadata["command"].toString();
+    QString url = _metadata["url"].toString();
+    QString type = _metadata["type"].toString();
+    QString filename = _metadata["filename"].toString();
 
-    if (_metadata["filename"].toString().isEmpty()) {
-        isValid = false;
+    if ((scheme == "xdg" || scheme == "xdgs")
+            && (command == "download" || command == "install")
+            && QUrl(url).isValid()
+            && _destinations.contains(type)
+            && !filename.isEmpty()) {
+        return true;
     }
 
-    return isValid;
+    return false;
 }
 
 void XdgUrl::process()
-- 
GitLab