diff options
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/uri.c | 14 | ||||
-rw-r--r-- | tests/good/manifest.nt | 54 | ||||
-rw-r--r-- | tests/good/manifest.ttl | 7 | ||||
-rw-r--r-- | tests/good/test-empty-path-base.nt | 1 | ||||
-rw-r--r-- | tests/good/test-empty-path-base.ttl | 3 |
6 files changed, 57 insertions, 25 deletions
@@ -1,8 +1,9 @@ serd (0.30.1) unstable; * Fix GCC 4 build + * Fix resolving some URIs against base URIs with no trailing slash - -- David Robillard <d@drobilla.net> Mon, 23 Jul 2018 23:14:40 +0200 + -- David Robillard <d@drobilla.net> Mon, 30 Jul 2018 19:28:32 +0200 serd (0.30.0) stable; @@ -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); } diff --git a/tests/good/manifest.nt b/tests/good/manifest.nt index ed9bcee0..553c193e 100644 --- a/tests/good/manifest.nt +++ b/tests/good/manifest.nt @@ -43,52 +43,54 @@ _:b20 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw _:b20 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b21 . _:b21 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-digit-start-pname> . _:b21 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b22 . -_:b22 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty> . +_:b22 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty-path-base> . _:b22 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b23 . -_:b23 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-eof-at-page-end> . +_:b23 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty> . _:b23 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b24 . -_:b24 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-escapes> . +_:b24 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-eof-at-page-end> . _:b24 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b25 . -_:b25 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-ext-namedblank-iri> . +_:b25 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-escapes> . _:b25 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b26 . -_:b26 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-ext-namedblank-prefix> . +_:b26 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-ext-namedblank-iri> . _:b26 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b27 . -_:b27 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-form-feed> . +_:b27 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-ext-namedblank-prefix> . _:b27 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b28 . -_:b28 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-id> . +_:b28 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-form-feed> . _:b28 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b29 . -_:b29 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-lang> . +_:b29 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-id> . _:b29 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b30 . -_:b30 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-list-in-blank> . +_:b30 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-lang> . _:b30 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b31 . -_:b31 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-list-subject> . +_:b31 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-list-in-blank> . _:b31 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b32 . -_:b32 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-list> . +_:b32 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-list-subject> . _:b32 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b33 . -_:b33 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-long-string> . +_:b33 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-list> . _:b33 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b34 . -_:b34 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-no-spaces> . +_:b34 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-long-string> . _:b34 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b35 . -_:b35 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-num> . +_:b35 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-no-spaces> . _:b35 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b36 . -_:b36 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-out-of-range-unicode> . +_:b36 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-num> . _:b36 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b37 . -_:b37 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-prefix> . +_:b37 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-out-of-range-unicode> . _:b37 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b38 . -_:b38 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-pretty> . +_:b38 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-prefix> . _:b38 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b39 . -_:b39 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-rel> . +_:b39 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-pretty> . _:b39 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b40 . -_:b40 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-semi-dot> . +_:b40 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-rel> . _:b40 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b41 . -_:b41 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-uri-escape> . +_:b41 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-semi-dot> . _:b41 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b42 . -_:b42 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-uri> . +_:b42 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-uri-escape> . _:b42 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b43 . -_:b43 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-utf8-uri> . +_:b43 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-uri> . _:b43 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b44 . -_:b44 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#UTF-8> . -_:b44 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> . +_:b44 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-utf8-uri> . +_:b44 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b45 . +_:b45 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://drobilla.net/sw/serd/tests/good/manifest.ttl#UTF-8> . +_:b45 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-14> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/rdftest#TestTurtleEval> . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-14> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name> "test-14" . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-14> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action> <http://drobilla.net/sw/serd/tests/good/test-14.ttl> . @@ -172,6 +174,10 @@ _:b44 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/ <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-digit-start-pname> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name> "test-digit-start-pname" . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-digit-start-pname> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action> <http://drobilla.net/sw/serd/tests/good/test-digit-start-pname.ttl> . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-digit-start-pname> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result> <http://drobilla.net/sw/serd/tests/good/test-digit-start-pname.nt> . +<http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty-path-base> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/rdftest#TestTurtleEval> . +<http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty-path-base> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name> "test-empty-path-base" . +<http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty-path-base> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action> <http://drobilla.net/sw/serd/tests/good/test-empty-path-base.ttl> . +<http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty-path-base> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#result> <http://drobilla.net/sw/serd/tests/good/test-empty-path-base.nt> . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/rdftest#TestTurtleEval> . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name> "test-empty" . <http://drobilla.net/sw/serd/tests/good/manifest.ttl#test-empty> <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action> <http://drobilla.net/sw/serd/tests/good/test-empty.ttl> . diff --git a/tests/good/manifest.ttl b/tests/good/manifest.ttl index 8bca9738..72012bbc 100644 --- a/tests/good/manifest.ttl +++ b/tests/good/manifest.ttl @@ -28,6 +28,7 @@ <#test-cr> <#test-delete> <#test-digit-start-pname> + <#test-empty-path-base> <#test-empty> <#test-eof-at-page-end> <#test-escapes> @@ -178,6 +179,12 @@ mf:action <test-digit-start-pname.ttl> ; mf:result <test-digit-start-pname.nt> . +<#test-empty-path-base> + rdf:type rdft:TestTurtleEval ; + mf:name "test-empty-path-base" ; + mf:action <test-empty-path-base.ttl> ; + mf:result <test-empty-path-base.nt> . + <#test-empty> rdf:type rdft:TestTurtleEval ; mf:name "test-empty" ; diff --git a/tests/good/test-empty-path-base.nt b/tests/good/test-empty-path-base.nt new file mode 100644 index 00000000..9ad50617 --- /dev/null +++ b/tests/good/test-empty-path-base.nt @@ -0,0 +1 @@ +<http://example.org/instance> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Thing> . diff --git a/tests/good/test-empty-path-base.ttl b/tests/good/test-empty-path-base.ttl new file mode 100644 index 00000000..a5cdd1e0 --- /dev/null +++ b/tests/good/test-empty-path-base.ttl @@ -0,0 +1,3 @@ +@base <http://example.org> . + +<instance> a <http://example.org/Thing> . |