[libiri] "@" parsing within autority when it's valid hierarchical part character
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 17 May 2013 09:09:37 +0000 (11:09 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 21 May 2013 07:48:53 +0000 (09:48 +0200)
[Issue#] LINUXWRT-338
[Problem] parseIRI bug
[Cause] Before "@" wasn't skipped in any case and treated as autority part always
[Solution] Add code for checking if "@" is in autority part of ti's hierarchical part character
[Verification] Build repo, use test binary from tests/.libs/iridump. IRI: should have host part correctly set.
IRI: http://mt1.googleapis.com/vt?lyrs=m@216094057&src=apiv3&hl=en&x=28717&s=&y=13011&z=15&s=Ga&scale=2&style=59,37%7Csmartmaps should have host part correctly set.

Change-Id: I0c5b5a4e4c7be1fe2e153fd3d0087b13cdc0d11e

libiri/parse.c

index ea12de7..2ed3e2f 100644 (file)
@@ -428,7 +428,7 @@ iri_parse(const char *src)
 {
        iri_t *p;
        char *bufstart, *endp, *bufp, **sl;
-       const char *at, *colon, *slash, *t;
+    const char *at, *colon, *slash, *t, *slash3rd;
        size_t buflen, sc, cp;
        
        if(NULL == (p = (iri_t *) calloc(1, sizeof(iri_t))))
@@ -450,6 +450,24 @@ iri_parse(const char *src)
                /* We can disregard the colon if a slash appears before it */
                colon = NULL;
        }
+    // "@" is valid character in hierarchical part of IRI
+    if(slash && colon && (colon[1] != '/' || colon[2] != '/'))
+    {
+        //if scheme not suffixed with ://, there is not autority
+        //therefore autority(and user within) is not set
+        at = NULL;
+    }
+    else if(at && slash && slash[1] && slash[2])
+    {
+        slash3rd = strchr(slash + 2, '/');
+        //here we know scheme suffix is "://" so autority can exist
+        //3rd slash should match start of hierarchical part if exists
+        //@ after that is valid character
+        if(slash3rd && slash3rd < at)
+        {
+            at = NULL;
+        }
+    }
        if(colon && !at)
        {
                /* Definitely a scheme */