Skip to content

Commit

Permalink
uri_parser: insert "//" after scheme is base uri have scheme "file"
Browse files Browse the repository at this point in the history
URIs file:///path/to/file.html have zero-width authority, but current code
thinks it doesn't exists at all. Since the only special case is file://
links, it's worth to simply add an exclusion.
  • Loading branch information
i-rinat committed Apr 26, 2015
1 parent d1c4327 commit 13854d9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/uri_parser/uri_parser.c
Expand Up @@ -238,12 +238,16 @@ uri_parser_merge_uris(const char *base_uri, const char *rel_uri)
str_t query = {};
str_t fragment = {};
GList *m = NULL; // list of allocated memory blocks
int scheme_is_file = 0;

uri_parser_parse_uri(base_uri, &base_c);

// if base_uri is local file, remove heading slashed from rel_uri to make it relative.
// That will emulate webserver root
if (base_c.scheme.len > 0 && strncmp(base_uri + base_c.scheme.begin, "file", 4) == 0) {
if (base_c.scheme.len > 0 && strncmp(base_uri + base_c.scheme.begin, "file", 4) == 0
&& base_c.scheme.len == 4)
{
scheme_is_file = 1;
while (rel_uri && *rel_uri == '/')
rel_uri ++;
}
Expand Down Expand Up @@ -300,7 +304,7 @@ uri_parser_merge_uris(const char *base_uri, const char *rel_uri)
"%.*s", // fragment
scheme.len, scheme.data,
scheme.len > 0 ? ":" : "",
authority.len > 0 ? "//" : "",
(authority.len > 0 || scheme_is_file) ? "//" : "",
authority.len, authority.data,
path.len, path.data,
query.len > 0 ? "?" : "",
Expand Down

0 comments on commit 13854d9

Please sign in to comment.