lib/url: fix no-scheme URL parsing
authorJeremy Kerr <jk@ozlabs.org>
Thu, 2 May 2013 09:30:55 +0000 (17:30 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 6 May 2013 01:02:12 +0000 (09:02 +0800)
We were incorrectly dropping the first strlen("file://") characters from
URLs with no scheme:

--- test/urls/data/localpath.test 2013-05-02 17:26:48.826359036 +0800
+++ /tmp/tmp.gn4JsWLw5o 2013-05-02 17:26:50.262364613 +0800
@@ -2,6 +2,6 @@
 scheme file
 host (null)
 port (null)
-path /test/path/to/local/file
-dir /test/path/to/local/
+path ath/to/local/file
+dir ath/to/local/
 file file

This change fixes the issue by indicating "no scheme found" by a NULL
return from pb_url_find_scheme, and hadling it appropriately. We add a
testcase too.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/url/url.c
test/urls/Makefile.am
test/urls/data/localpath.test [new file with mode: 0644]

index ae72b103de62153e2a8e779286c7a8d3a01d2a55..1e69774efb4e2a230d8cf24ca0dcd1973b699dcf 100644 (file)
@@ -129,9 +129,7 @@ static const struct pb_scheme_info *pb_url_find_scheme(const char *url)
                return scheme;
        }
 
-       /* Assume this is a non-url local file. */
-
-       return file_scheme;
+       return NULL;
 }
 
 static void pb_url_parse_path(struct pb_url *url)
@@ -177,9 +175,13 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str)
                return NULL;
 
        si = pb_url_find_scheme(url_str);
-
-       url->scheme = si->scheme;
-       p = url_str + si->str_len + strlen("://");
+       if (si) {
+               url->scheme = si->scheme;
+               p = url_str + si->str_len + strlen("://");
+       } else {
+               url->scheme = file_scheme->scheme;
+               p = url_str;
+       }
 
        url->full = talloc_strdup(url, url_str);
 
index 21630181e8398b9bb2a0e3deb8da2c3fd44119af..da6fcbfbcc4d0c5dd2a2b276172e2ea9d00a8929 100644 (file)
@@ -33,7 +33,8 @@ TESTS = data/double-slash.test \
        data/http-simple.test \
        data/join-full.test \
        data/join-absolute.test \
-       data/join-relative.test
+       data/join-relative.test \
+       data/localpath.test
 
 TEST_EXTENSIONS = .test
 TEST_LOG_COMPILER = $(builddir)/run-url-test
diff --git a/test/urls/data/localpath.test b/test/urls/data/localpath.test
new file mode 100644 (file)
index 0000000..ffced1a
--- /dev/null
@@ -0,0 +1,7 @@
+/test/path/to/local/file
+scheme file
+host   (null)
+port   (null)
+path   /test/path/to/local/file
+dir    /test/path/to/local/
+file   file