aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-07-30 19:30:34 +0200
committerDavid Robillard <d@drobilla.net>2018-07-30 19:31:03 +0200
commit3267bb312f50746202226d29cc196bb47941e4d5 (patch)
treeff7de7db894279e73090d46c57313f994b7139e8 /src
parent8acc3319d2df2dbd2490843e1d49439ee20a0780 (diff)
downloadserd-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')
-rw-r--r--src/uri.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/uri.c b/src/uri.c
index 8b3c3c3a..0f0b3ca6 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -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);
}