From f93c3fdd6c7d6ca61bec55d3c1ffae7e7c793913 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 29 Mar 2023 19:59:50 -0400 Subject: Fix relative URI creation --- src/uri.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/uri.c') diff --git a/src/uri.c b/src/uri.c index 8acb79b3..dcdd8083 100644 --- a/src/uri.c +++ b/src/uri.c @@ -1,4 +1,4 @@ -// Copyright 2011-2020 David Robillard +// Copyright 2011-2023 David Robillard // SPDX-License-Identifier: ISC #include "string_utils.h" @@ -428,10 +428,6 @@ write_rel_path(SerdSink sink, len += sink("../", 3, stream); } - if (last_shared_sep == 0 && up == 0) { - len += sink("/", 1, stream); - } - // Write suffix return len + write_path_tail(sink, stream, uri, last_shared_sep + 1); } @@ -468,8 +464,12 @@ serd_uri_serialise_relative(const SerdURI* const uri, if (uri->authority.buf) { len += sink("//", 2, stream); len += sink(uri->authority.buf, uri->authority.len, stream); - if (uri->authority.len > 0 && - uri->authority.buf[uri->authority.len - 1] != '/' && + + const bool authority_ends_with_slash = + (uri->authority.len > 0 && + uri->authority.buf[uri->authority.len - 1] == '/'); + + if (!authority_ends_with_slash && serd_uri_path_starts_without_slash(uri)) { // Special case: ensure path begins with a slash // https://tools.ietf.org/html/rfc3986#section-3.2 -- cgit v1.2.1