diff options
author | David Robillard <d@drobilla.net> | 2018-07-30 19:30:34 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-07-30 19:31:03 +0200 |
commit | 3267bb312f50746202226d29cc196bb47941e4d5 (patch) | |
tree | ff7de7db894279e73090d46c57313f994b7139e8 /src/uri.c | |
parent | 8acc3319d2df2dbd2490843e1d49439ee20a0780 (diff) | |
download | serd-3267bb312f50746202226d29cc196bb47941e4d5.tar.gz serd-3267bb312f50746202226d29cc196bb47941e4d5.tar.bz2 serd-3267bb312f50746202226d29cc196bb47941e4d5.zip |
Fix resolving some URIs against base URIs with no trailing slash
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -452,6 +452,14 @@ write_rel_path(SerdSink sink, return len += write_path_tail(sink, stream, uri, last_shared_sep + 1); } +static uint8_t +serd_uri_path_starts_without_slash(const SerdURI* uri) +{ + return ((uri->path_base.len || uri->path.len) && + ((!uri->path_base.len || uri->path_base.buf[0] != '/') && + (!uri->path.len || uri->path.buf[0] != '/'))); +} + /// See http://tools.ietf.org/html/rfc3986#section-5.3 size_t serd_uri_serialise_relative(const SerdURI* uri, @@ -475,6 +483,12 @@ serd_uri_serialise_relative(const SerdURI* uri, if (uri->authority.buf) { len += sink("//", 2, stream); len += sink(uri->authority.buf, uri->authority.len, stream); + if (uri->authority.buf[uri->authority.len - 1] != '/' && + serd_uri_path_starts_without_slash(uri)) { + // Special case: ensure path begins with a slash + // https://tools.ietf.org/html/rfc3986#section-3.2 + len += sink("/", 1, stream); + } } len += write_path_tail(sink, stream, uri, 0); } |