From 621d135c90bd5e44c12f5443f54554792f2117ea Mon Sep 17 00:00:00 2001
From: Benoit Mortier <benoit.mortier@opensides.be>
Date: Thu, 22 Nov 2012 16:07:43 +0100
Subject: [PATCH] Fixes: #1352 Some tests::is_url should be checked

---
 include/class_tests.inc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/class_tests.inc b/include/class_tests.inc
index 6245153b2..bbfd623ef 100644
--- a/include/class_tests.inc
+++ b/include/class_tests.inc
@@ -70,7 +70,7 @@ class tests {
   /*!
    * \brief Test if the given string contains characters allowed in a hostname
    *
-   * \param string $str The hostname to check 
+   * \param string $str The hostname to check
    */
   public static function is_valid_hostname($str)
   {
@@ -85,11 +85,12 @@ class tests {
    */
   public static function is_url($url)
   {
-    if ($url == ""){
-      return (TRUE);
+    if ($url == "") {
+      return TRUE;
     }
 
-    return preg_match ("/^(http|https):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/", $url);
+    /* Using @stephenhay regexp from http://mathiasbynens.be/demo/url-regex (removed ftp through) */
+    return preg_match ("@^(https?)://[^\s/$.?#].[^\s]*$@i", $url);
   }
 
 
-- 
GitLab