diff options
author | David Robillard <d@drobilla.net> | 2018-05-11 15:28:43 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-05-27 18:23:15 +0200 |
commit | 1f4990c7d2e297dc0252ff193e66339d8db38837 (patch) | |
tree | 75bd7f48b02bcbeba0ce4ecb991a957b3ac4aaaa | |
parent | ca7747e16dbcf7395d73f5292394cf37a4748604 (diff) | |
download | serd-1f4990c7d2e297dc0252ff193e66339d8db38837.tar.gz serd-1f4990c7d2e297dc0252ff193e66339d8db38837.tar.bz2 serd-1f4990c7d2e297dc0252ff193e66339d8db38837.zip |
Fix rooted relative URI serialisation
-rw-r--r-- | src/uri.c | 6 | ||||
-rw-r--r-- | src/uri_utils.h | 13 |
2 files changed, 14 insertions, 5 deletions
@@ -437,8 +437,10 @@ serd_uri_serialise_relative(const SerdURI* uri, SerdSink sink, void* stream) { - size_t len = 0; - const bool relative = uri_is_under(uri, root ? root : base); + size_t len = 0; + const bool relative = + root ? uri_is_under(uri, root) : uri_is_related(uri, base); + if (relative) { len = write_rel_path(sink, stream, uri, base); } diff --git a/src/uri_utils.h b/src/uri_utils.h index a22bc7bf..bf5ec3d9 100644 --- a/src/uri_utils.h +++ b/src/uri_utils.h @@ -44,11 +44,11 @@ uri_path_at(const SerdURI* uri, size_t i) } } -/** Return true iff `uri` is within the base of `root` */ +/** Return true iff `uri` shares path components with `root` */ static inline bool -uri_is_under(const SerdURI* uri, const SerdURI* root) +uri_is_related(const SerdURI* uri, const SerdURI* root) { - if (!root || !root->scheme.len || + if (!root || !root->scheme.len || uri->path.len == 1 || !slice_equals(&root->scheme, &uri->scheme) || !slice_equals(&root->authority, &uri->authority)) { return false; @@ -69,6 +69,13 @@ uri_is_under(const SerdURI* uri, const SerdURI* root) return true; } +/** Return true iff `uri` is within the base of `root` */ +static inline bool +uri_is_under(const SerdURI* uri, const SerdURI* root) +{ + return uri->path.len >= root->path.len && uri_is_related(uri, root); +} + static inline bool is_uri_scheme_char(const uint8_t c) { |