]> granicus.if.org Git - php/commitdiff
Fixed bug #25800 (parse_url() could not parse urls with empty port).
authorIlia Alshanetsky <iliaa@php.net>
Mon, 13 Oct 2003 04:27:23 +0000 (04:27 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 13 Oct 2003 04:27:23 +0000 (04:27 +0000)
ext/standard/tests/strings/url_t.phpt
ext/standard/url.c

index 78a6706f5416a0f2638870dcb1eedc8c0bcb3f24..1af113a69505420465340bfc7c045986b56e6bfe 100644 (file)
@@ -64,7 +64,11 @@ $sample_urls = array (
 'mailto:me@mydomain.com',
 '/foo.php?a=b&c=d',
 'foo.php?a=b&c=d',
-'http://user:passwd@www.example.com:8080?bar=1&boom=0'
+'http://user:passwd@www.example.com:8080?bar=1&boom=0',
+'file:///path/to/file',
+'file://path/to/file',
+'file:/path/to/file',
+'http://1.2.3.4:/abc.asp?a=1&b=2'
 );
 
     foreach ($sample_urls as $url) {
@@ -616,3 +620,33 @@ array(6) {
   ["query"]=>
   string(12) "bar=1&boom=0"
 }
+array(2) {
+  ["scheme"]=>
+  string(4) "file"
+  ["path"]=>
+  string(13) "/path/to/file"
+}
+array(3) {
+  ["scheme"]=>
+  string(4) "file"
+  ["host"]=>
+  string(4) "path"
+  ["path"]=>
+  string(8) "/to/file"
+}
+array(2) {
+  ["scheme"]=>
+  string(4) "file"
+  ["path"]=>
+  string(13) "/path/to/file"
+}
+array(4) {
+  ["scheme"]=>
+  string(4) "http"
+  ["host"]=>
+  string(7) "1.2.3.4"
+  ["path"]=>
+  string(8) "/abc.asp"
+  ["query"]=>
+  string(7) "a=1&b=2"
+}
index 3da9f66d940118522309a6a61ce5df22a39f62d8..cdddbf00f1e8b172a81f596f6fca3b700c999197 100644 (file)
@@ -197,17 +197,17 @@ PHPAPI php_url *php_url_parse(char *str)
        if ((p = memchr(s, ':', (e-s)))) {
                if (!ret->port) {
                        p++;
-                       if ( e-p > 5 || e-p < 1 ) { /* port cannot be longer then 5 characters */
+                       if (e-p > 5) { /* port cannot be longer then 5 characters */
                                STR_FREE(ret->scheme);
                                STR_FREE(ret->user);
                                STR_FREE(ret->pass);
                                efree(ret);
                                return NULL;
+                       } else if (e - p > 0) {
+                               memcpy(port_buf, p, (e-p));
+                               port_buf[e-p] = '\0';
+                               ret->port = atoi(port_buf);
                        }
-               
-                       memcpy(port_buf, p, (e-p));
-                       port_buf[e-p] = '\0';
-                       ret->port = atoi(port_buf);
                        p--;
                }       
        } else {