Skip to content

Commit

Permalink
Support relative_to on URNs
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Jan 6, 2025
1 parent 69d5a7a commit 590730b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/uri/uri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/uri/uri_relative_to_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 590730b

Please sign in to comment.