[libsoup] soup-uri: fix URI scheme parsing



commit 2e436f5c75fcff49518a33eee6429a23f556ec6d
Author: Dan Winship <danw gnome org>
Date:   Sat Jul 13 11:55:00 2013 -0400

    soup-uri: fix URI scheme parsing
    
    The URI grammar allows a scheme to have digits in it after the first
    character, and doesn't allow [.+-] in the first character.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703776

 libsoup/soup-uri.c  |    7 +++++--
 tests/uri-parsing.c |   16 ++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index b9ff93f..16098f6 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -263,10 +263,13 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
                end = hash;
        }
 
-       /* Find scheme: initial [a-z+.-]* substring until ":" */
+       /* Find scheme */
        p = uri_string;
        while (p < end && (g_ascii_isalpha (*p) ||
-                          *p == '.' || *p == '+' || *p == '-'))
+                          (p > uri_string && (g_ascii_isdigit (*p) ||
+                                              *p == '.' ||
+                                              *p == '+' ||
+                                              *p == '-'))))
                p++;
 
        if (p > uri_string && *p == ':') {
diff --git a/tests/uri-parsing.c b/tests/uri-parsing.c
index 892ee2b..d1bba4e 100644
--- a/tests/uri-parsing.c
+++ b/tests/uri-parsing.c
@@ -128,6 +128,22 @@ static struct {
 
        { "http://host/keep%00nuls";, "http://host/keep%00nuls";,
          { "http", NULL, NULL, "host", 80, "/keep%00nuls", NULL, NULL } },
+
+       /* Bug 703776; scheme parsing */
+       { "foo0://host/path", "foo0://host/path",
+         { "foo0", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+       { "f0.o://host/path", "f0.o://host/path",
+         { "f0.o", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+       { "http++://host/path", "http++://host/path",
+         { "http++", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+       { "http-ish://host/path", "http-ish://host/path",
+         { "http-ish", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+       { "99http://host/path";, NULL,
+         { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL } },
+       { ".http://host/path";, NULL,
+         { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL } },
+       { "+http://host/path";, NULL,
+         { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL } },
 };
 static int num_abs_tests = G_N_ELEMENTS(abs_tests);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]