iliaa           Thu Nov  7 10:41:32 2002 EDT

  Modified files:              
    /php4/ext/standard  url.c 
  Log:
  parse_url can now correctly parse mailto:, zlib: (old zlib wrapper) and 
  simular. Thanks to Wez Furlong for noticing the problem.
  
  
Index: php4/ext/standard/url.c
diff -u php4/ext/standard/url.c:1.57 php4/ext/standard/url.c:1.58
--- php4/ext/standard/url.c:1.57        Fri Oct 18 19:54:58 2002
+++ php4/ext/standard/url.c     Thu Nov  7 10:41:32 2002
@@ -15,7 +15,7 @@
    | Author: Jim Winstead <[EMAIL PROTECTED]>                                  |
    +----------------------------------------------------------------------+
  */
-/* $Id: url.c,v 1.57 2002/10/18 23:54:58 iliaa Exp $ */
+/* $Id: url.c,v 1.58 2002/11/07 15:41:32 iliaa Exp $ */
 
 #include <stdlib.h>
 #include <string.h>
@@ -94,19 +94,49 @@
        ue = s + length;
 
        /* parse scheme */
-       if ((e = strchr(s, ':')) && *(e+1) == '/' && (e-s)) {
-               ret->scheme = estrndup(s, (e-s));
-               php_replace_controlchars(ret->scheme);
-               
-               if (*(e+2) == '/') {
-                       s = e + 3;
+       if ((e = strchr(s, ':')) && (e-s)) {
+               /* 
+                * certain schemas like mailto: and zlib: may not have any / after them
+                * this check ensures we support those.
+                */
+               if (*(e+1) != '/') {
+                       /* check if the data we get is a port this allows us to 
+                        * correctly parse things like a.com:80
+                        */
+                       p = e + 1;
+                       while (isdigit(*p)) {
+                               p++;
+                       }
+                       
+                       if ((*p) == '\0' || *p == '/') {
+                               goto parse_port;
+                       }
+                       
+                       ret->scheme = estrndup(s, (e-s));
+                       php_replace_controlchars(ret->scheme);
+                       
+                       length -= ++e - s;
+                       s = e;
+                       goto just_path;
                } else {
-                       s = e + 1;
-                       if (!strncasecmp("file", ret->scheme, sizeof("file"))) {
-                               goto nohost;
-                       }       
+                       ret->scheme = estrndup(s, (e-s));
+                       php_replace_controlchars(ret->scheme);
+               
+                       if (*(e+2) == '/') {
+                               s = e + 3;
+                       } else {
+                               s = e + 1;
+                               if (!strncasecmp("file", ret->scheme, sizeof("file"))) 
+{
+                                       goto nohost;
+                               } else {
+                                       length -= ++e - s;
+                                       s = e;
+                                       goto just_path;
+                               }       
+                       }
                }       
        } else if (e) { /* no scheme, look for port */
+               parse_port:
                p = e + 1;
                pp = p;
                
@@ -123,13 +153,15 @@
                }
        } else {
                just_path:
-               ret->path = estrndup(str, length);
+               ret->path = estrndup(s, length);
                php_replace_controlchars(ret->path);
                return ret;
        }
        
        if (!(e = strchr(s, '/'))) {
                e = ue;
+       } else if (e && e == s) {
+               e = ue;
        }
 
        /* check for login and password */
@@ -145,6 +177,9 @@
                                ret->pass = estrndup(pp, (p-pp));
                                php_replace_controlchars(ret->pass);
                        }       
+               } else {
+                       ret->user = estrndup(s, (p-s));
+                       php_replace_controlchars(ret->user);
                }
                
                s = p + 1;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to