[gnome-maps] utils: Fix URL validity check



commit 515cc2e0a4b92b0f92c618dfeee57882c2e9dc6f
Author: Ravi Shankar <ravishankar98910 gmail com>
Date:   Sun Dec 13 13:32:14 2020 +0530

    utils: Fix URL validity check
    
    The utility function to detect a valid URL does not take
    into account the // followed by the URL scheme,
    so a simple string matching is used instead.
    The test/utilsTest.js is also modified to include test-case
    which fails with the GUri parser, but is a valid
    test case for URL.
    
    Fixes #318

 src/utils.js       | 4 +---
 tests/utilsTest.js | 1 +
 2 files changed, 2 insertions(+), 3 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index 12c54f14..725bc2e4 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -465,7 +465,5 @@ function isValidWebsite(website) {
     } catch(e) {
         return false;
     }
-
-    let scheme = GLib.Uri.parse_scheme(website);
-    return scheme === "http" || scheme === "https";
+    return website.startsWith("http://";) || website.startsWith("https://";);
 }
diff --git a/tests/utilsTest.js b/tests/utilsTest.js
index 7cdf905e..fe4834ee 100644
--- a/tests/utilsTest.js
+++ b/tests/utilsTest.js
@@ -108,4 +108,5 @@ function validWebsiteTest() {
     JsUnit.assertEquals(true, Utils.isValidWebsite("http://gnome.org";));
     JsUnit.assertEquals(false, Utils.isValidWebsite("ftp://gnome.org";));
     JsUnit.assertEquals(false, Utils.isValidWebsite("www.gnome.org"));
+    JsUnit.assertEquals(false, Utils.isValidWebsite("https:gnome.org"));
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]