apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r594624 - in /apr/apr-util/trunk: test/testuri.c uri/apr_uri.c
Date Tue, 13 Nov 2007 20:00:35 GMT
Author: pquerna
Date: Tue Nov 13 12:00:34 2007
New Revision: 594624

URL: http://svn.apache.org/viewvc?rev=594624&view=rev
Log:
Add better scheme/host parsing to apr_uri.

Submitted by: Henry Jen <henryjen ztune.net>

Modified:
    apr/apr-util/trunk/test/testuri.c
    apr/apr-util/trunk/uri/apr_uri.c

Modified: apr/apr-util/trunk/test/testuri.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testuri.c?rev=594624&r1=594623&r2=594624&view=diff
==============================================================================
--- apr/apr-util/trunk/test/testuri.c (original)
+++ apr/apr-util/trunk/test/testuri.c Tue Nov 13 12:00:34 2007
@@ -95,6 +95,30 @@
         "//www.apache.org/",
         0, NULL, "www.apache.org", NULL, NULL, "www.apache.org", NULL, "/", NULL, NULL, 0
     },
+    {
+        "file:image.jpg",
+        0, "file", NULL, NULL, NULL, NULL, NULL, "image.jpg", NULL, NULL, 0
+    },
+    {
+        "file:/image.jpg",
+        0, "file", NULL, NULL, NULL, NULL, NULL, "/image.jpg", NULL, NULL, 0
+    },
+    {
+        "file:///image.jpg",
+        0, "file", "", NULL, NULL, "", NULL, "/image.jpg", NULL, NULL, 0
+    },
+    {
+        "file:///tmp/photos/image.jpg",
+        0, "file", "", NULL, NULL, "", NULL, "/tmp/photos/image.jpg", NULL, NULL, 0
+    },
+    {
+        "file:./image.jpg",
+        0, "file", NULL, NULL, NULL, NULL, NULL, "./image.jpg", NULL, NULL, 0
+    },
+    {
+        "file:../photos/image.jpg",
+        0, "file", NULL, NULL, NULL, NULL, NULL, "../photos/image.jpg", NULL, NULL, 0
+    },
 };
 
 struct uph_test {

Modified: apr/apr-util/trunk/uri/apr_uri.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/uri/apr_uri.c?rev=594624&r1=594623&r2=594624&view=diff
==============================================================================
--- apr/apr-util/trunk/uri/apr_uri.c (original)
+++ apr/apr-util/trunk/uri/apr_uri.c Tue Nov 13 12:00:34 2007
@@ -92,6 +92,12 @@
                                     unsigned flags)
 {
     char *ret = "";
+    char *scheme = NULL;
+
+    if (uptr->scheme) {
+        scheme = apr_pstrcat(p, uptr->scheme, ":", NULL);
+    }
+
 
     /* If suppressing the site part, omit both user name & scheme://hostname */
     if (!(flags & APR_URI_UNP_OMITSITEPART)) {
@@ -129,29 +135,15 @@
                  uptr->port == 0 ||
                  uptr->port == apr_uri_port_of_scheme(uptr->scheme));
 
-            if (uptr->scheme) {
-                ret = apr_pstrcat(p,
-                              uptr->scheme, "://", ret,
-                              lbrk, uptr->hostname, rbrk,
-                              is_default_port ? "" : ":",
-                              is_default_port ? "" : uptr->port_str,
-                              NULL);
-            }
-            else {
-                /* A violation of RFC2396, but it is clear from section 3.2
-                 * that the : belongs above to the scheme, while // belongs
-                 * to the authority, so include the authority prefix while
-                 * omitting the "scheme:" that the user neglected to pass us.
-                 */
-                ret = apr_pstrcat(p,
-                              "//", ret, lbrk, uptr->hostname, rbrk,
-                              is_default_port ? "" : ":",
-                              is_default_port ? "" : uptr->port_str,
-                              NULL);
-            }
+            ret = apr_pstrcat(p, "//", ret, lbrk, uptr->hostname, rbrk,
+                        is_default_port ? "" : ":",
+                        is_default_port ? "" : uptr->port_str,
+                        NULL);
         }
     }
 
+    ret = apr_pstrcat(p, scheme ? scheme : "", ret, NULL);
+    
     /* Should we suppress all path info? */
     if (!(flags & APR_URI_UNP_OMITPATHINFO)) {
         /* Append path, query and fragment strings: */
@@ -324,12 +316,17 @@
     while ((uri_delims[*(unsigned char *)s] & NOTEND_SCHEME) == 0) {
         ++s;
     }
-    /* scheme must be non-empty and followed by :// */
-    if (s == uri || s[0] != ':' || s[1] != '/' || s[2] != '/') {
+    /* scheme must be non-empty and followed by : */
+    if (s == uri || s[0] != ':') {
         goto deal_with_path;        /* backwards predicted taken! */
     }
 
     uptr->scheme = apr_pstrmemdup(p, uri, s - uri);
+    if (s[1] != '/' || s[2] != '/') {
+        uri = s + 1;
+        goto deal_with_path;
+    }
+
     s += 3;
 
 deal_with_authority:



Mime
View raw message