diff options
Diffstat (limited to 'src')
-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) { |