if the protocol is http or https, require a hostname. For #61049
authorDan Winship <danw@src.gnome.org>
Wed, 7 Jul 2004 15:27:24 +0000 (15:27 +0000)
committerDan Winship <danw@src.gnome.org>
Wed, 7 Jul 2004 15:27:24 +0000 (15:27 +0000)
        * libsoup/soup-uri.c (soup_uri_new_with_base): if the protocol is
        http or https, require a hostname. For #61049

        * tests/uri-parsing.c (rel_tests, do_uri): Update for that

ChangeLog
libsoup/soup-uri.c
tests/uri-parsing.c

index 91f8f62..3fc2fe6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-07-06  Dan Winship  <danw@novell.com>
+
+       * libsoup/soup-uri.c (soup_uri_new_with_base): if the protocol is
+       http or https, require a hostname. For #61049
+
+       * tests/uri-parsing.c (rel_tests, do_uri): Update for that
+
 2004-06-03  JP Rosevear <jpr@novell.com>
 
        * configure.in: bump version to 2.1.11, libtool number
index 5461bbb..ea7d09d 100644 (file)
@@ -216,6 +216,13 @@ soup_uri_new_with_base (const SoupUri *base, const char *uri_string)
                }
        }
 
+       /* Sanity check */
+       if ((uri->protocol == SOUP_PROTOCOL_HTTP ||
+            uri->protocol == SOUP_PROTOCOL_HTTPS) && !uri->host) {
+               soup_uri_free (uri);
+               return NULL;
+       }
+
        if (!uri->port)
                uri->port = soup_protocol_default_port (uri->protocol);
        if (!uri->path)
index 5bd43be..3cadfd7 100644 (file)
@@ -69,7 +69,14 @@ struct {
        { "g?y/../x", "http://a/b/c/g?y/../x" },
        { "g#s/./x", "http://a/b/c/g#s/./x" },
        { "g#s/../x", "http://a/b/c/g#s/../x" },
-       { "http:g", "http:g" }
+
+       /* RFC 2396 notes that some old parsers will parse this as
+        * a relative URL ("http://a/b/c/g"), but it should be
+        * interpreted as absolute. libsoup should parse it
+        * correctly as being absolute, but then reject it since it's
+        * an http URL with no host.
+        */
+       { "http:g", NULL }
 };
 int num_rel_tests = G_N_ELEMENTS(rel_tests);
 
@@ -81,21 +88,33 @@ do_uri (SoupUri *base_uri, const char *base_str,
        char *uri_string;
 
        if (base_uri) {
-               printf ("<%s> + <%s> = <%s>? ", base_str, in_uri, out_uri);
+               printf ("<%s> + <%s> = <%s>? ", base_str, in_uri,
+                       out_uri ? out_uri : "ERR");
                uri = soup_uri_new_with_base (base_uri, in_uri);
        } else {
-               printf ("<%s> => <%s>? ", in_uri, out_uri);
+               printf ("<%s> => <%s>? ", in_uri,
+                       out_uri ? out_uri : "ERR");
                uri = soup_uri_new (in_uri);
        }
 
        if (!uri) {
-               printf ("ERR\n  Could not parse %s\n", in_uri);
-               return FALSE;
+               if (out_uri) {
+                       printf ("ERR\n  Could not parse %s\n", in_uri);
+                       return FALSE;
+               } else {
+                       printf ("OK\n");
+                       return TRUE;
+               }
        }
 
        uri_string = soup_uri_to_string (uri, FALSE);
        soup_uri_free (uri);
 
+       if (!out_uri) {
+               printf ("ERR\n  Got %s\n", uri_string);
+               return FALSE;
+       }
+
        if (strcmp (uri_string, out_uri) != 0) {
                printf ("NO\n  Unparses to <%s>\n", uri_string);
                g_free (uri_string);