From 590730b14f915982f4a50f3c81bc1442c65c48a2 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 6 Jan 2025 13:42:27 -0400 Subject: [PATCH] Support `relative_to` on URNs Signed-off-by: Juan Cruz Viotti --- src/uri/uri.cc | 6 ++++++ test/uri/uri_relative_to_test.cc | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/uri/uri.cc b/src/uri/uri.cc index e069cd461..c34cdcb46 100644 --- a/src/uri/uri.cc +++ b/src/uri/uri.cc @@ -514,6 +514,12 @@ auto URI::relative_to(const URI &base) -> URI & { } uriFreeUriMembersMmA(&result, nullptr); + + // TODO: Why do we even need to do this? + if (copy.data.starts_with('/')) { + copy.data.erase(0, 1); + } + copy.parse(); // `uriparser` has this weird thing where it will only look at scheme and diff --git a/test/uri/uri_relative_to_test.cc b/test/uri/uri_relative_to_test.cc index 7e0770b4b..54db19b74 100644 --- a/test/uri/uri_relative_to_test.cc +++ b/test/uri/uri_relative_to_test.cc @@ -77,3 +77,10 @@ TEST(URI_relative_to, relative_relative_1) { uri.relative_to(base); EXPECT_EQ(uri.recompose(), "foo/bar/baz"); } + +TEST(URI_relative_to, urn_1) { + const sourcemeta::jsontoolkit::URI base{"schema:"}; + sourcemeta::jsontoolkit::URI uri{"schema:myschema"}; + uri.relative_to(base); + EXPECT_EQ(uri.recompose(), "myschema"); +}