aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-11 15:28:43 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 18:23:15 +0200
commit1f4990c7d2e297dc0252ff193e66339d8db38837 (patch)
tree75bd7f48b02bcbeba0ce4ecb991a957b3ac4aaaa
parentca7747e16dbcf7395d73f5292394cf37a4748604 (diff)
downloadserd-1f4990c7d2e297dc0252ff193e66339d8db38837.tar.gz
serd-1f4990c7d2e297dc0252ff193e66339d8db38837.tar.bz2
serd-1f4990c7d2e297dc0252ff193e66339d8db38837.zip
Fix rooted relative URI serialisation
-rw-r--r--src/uri.c6
-rw-r--r--src/uri_utils.h13
2 files changed, 14 insertions, 5 deletions
diff --git a/src/uri.c b/src/uri.c
index b254bea6..096a45e4 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -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)
{