Skip to content

uri-validation does not accept hyphens in path #2

@netzkind

Description

@netzkind

When running LiveTest 1.0.1 against uris with hyphens in the path, LiveTest fails with "does not represent a valid uri".

Can be reproduced for example with the following URI:
http://www.deine-tierwelt.de/kleinanzeigen/rassehunde-c4146/

Fix for src/lib/Base/Www/Uri.php:

@@ -60,13 +60,13 @@
      * @todo: Check if Zend_Validator_Callback can do the same.
      * Used from: http://phpcentral.com/208-url-validation-in-php.html#post576
     */
-    $urlregex = "^((https?|ftp)\:\/\/)?";
+    $urlregex = "^((https?|ftp)\://)?";

     // USER AND PASS (optional)
-    $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?";
+    $urlregex .= "([a-z0-9+!*(),;?&=\$_.\-]+(\:[a-z0-9+!*(),;?&=\$_.\-]+)?@)?";

     // HOSTNAME OR IP
-    $urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin)
+    $urlregex .= "[a-z0-9+\$_\-]+(\.[a-z0-9+\$_\-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin)
     //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)+"; // http://x.x = minimum
     //$urlregex .= "([a-z0-9+\$_-]+\.)*[a-z0-9+\$_-]{2,3}"; // http://x.xx(x) = minimum
     //use only one of the above
@@ -74,11 +74,11 @@
     // PORT (optional)
     $urlregex .= "(\:[0-9]{2,5})?";
     // PATH (optional)
-    $urlregex .= "(\/([a-z0-9+\$_-~]\.?)+)*\/?";
+    $urlregex .= "(/([a-z0-9+\$_\-~]\.?)+)*/?";
     // GET Query (optional)
-    $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?";
+    $urlregex .= "(\?[a-z+&\$_.\-][a-z0-9;:@/&%=+\$_.\-]*)?";
     // ANCHOR (optional)
-    $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
+    $urlregex .= "(#[a-z_.\-][a-z0-9+\$_.\-]*)?\$";

     $urlregex = "¤" . $urlregex . "¤";
 ;    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions