Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/uri/uri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ auto URI::recompose() const -> std::string {
++iterator) {
// TODO: We shouldn't need to manually do these look-aheads here.
// It should all be taking care off by the escaper logic

// TODO: There is also a caveat here: what if we have "foo%bar"?
if (*iterator == '%') {
auto next_1 = std::next(iterator, 1);
auto next_2 = std::next(iterator, 2);
Expand Down
7 changes: 7 additions & 0 deletions test/jsonpointer/jsonpointer_to_uri_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ TEST(JSONPointer_to_uri, with_absolute_base) {
EXPECT_EQ(fragment.recompose(), "https://www.example.com#/foo/bar");
}

TEST(JSONPointer_to_uri, with_absolute_base_percentage) {
const sourcemeta::core::Pointer pointer{"foo%bar"};
const sourcemeta::core::URI base{"https://www.example.com"};
const sourcemeta::core::URI fragment{sourcemeta::core::to_uri(pointer, base)};
EXPECT_EQ(fragment.recompose(), "https://www.example.com#/foo%25bar");
}

TEST(JSONPointer_to_uri, with_relative_base) {
const sourcemeta::core::Pointer pointer{"foo", "bar"};
const sourcemeta::core::URI base{"../baz"};
Expand Down
8 changes: 8 additions & 0 deletions test/uri/uri_fragment_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,11 @@ TEST(URI_fragment, set_pointer_bracket) {
EXPECT_EQ(uri.fragment(), "/[foo/bar");
EXPECT_EQ(uri.recompose(), "https://www.sourcemeta.com#/%5Bfoo/bar");
}

TEST(URI_fragment, set_pointer_percentage) {
sourcemeta::core::URI uri{"https://www.sourcemeta.com"};
uri.fragment("/foo%bar");
// Escaping should only happen during recomposing
EXPECT_EQ(uri.fragment(), "/foo%bar");
EXPECT_EQ(uri.recompose(), "https://www.sourcemeta.com#/foo%25bar");
}
7 changes: 7 additions & 0 deletions test/uri/uri_parse_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ TEST(URI_parse, syntax_error_4) {
sourcemeta::core::URIParseError);
}

TEST(URI_parse, syntax_error_5) {
EXPECT_THROW(
sourcemeta::core::URI uri{
"https://www.example.com#/foo%bar"}, // unescaped "%"
sourcemeta::core::URIParseError);
}

// Inspired from
// https://github.com/uriparser/uriparser/blob/bf0174e83164a4659c51c135399478bec389eafa/test/test.cpp#L315

Expand Down
Loading