Skip to content

Commit

Permalink
Fix issue jsonschema with keys with illegal fragment characters
Browse files Browse the repository at this point in the history
danielaparker committed Dec 5, 2024
1 parent b6ecc12 commit 151c917
Showing 7 changed files with 37 additions and 36 deletions.
54 changes: 29 additions & 25 deletions doc/ref/corelib/uri.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@ The class `uri` represents a Uniform Resource Identifier (URI) reference.

uri();

uri(const std::string& s);
Constructs a URI by parsing the given string.

uri(const std::string& uri);
Constructs a URI by parsing the given string.

@@ -20,7 +23,7 @@ Constructs a URI by parsing the given string.
jsoncons::string_view path,
jsoncons::string_view query,
jsoncons::string_view fragment)
Constructs a URI from the given components.
Constructs a URI from the given non-encoded parts.

uri(const uri& other);

@@ -34,58 +37,59 @@ Constructs a URI from the given components.

#### Member functions

bool is_absolute() const noexcept;
Returns true if this URI is absolute, false otherwise. An absolute URI is a URI that has
a scheme part (the part after the colon), e.g. 'https://john.doe@www.example.com'.

bool is_opaque() const noexcept;
Returns true if this URI is opaque, false otherwise. An opaque URI is an absolute URI whose
scheme-specific part does not begin with a slash character ('/'), e.g. 'mailto:john.doe@example.com'.

uri base() const noexcept;

const std::string& string() const;

jsoncons::string_view scheme() const noexcept;

jsoncons::string_view scheme() const noexcept;

jsoncons::string_view encoded_scheme() const noexcept;
Returns the scheme part of this URI. The scheme is the first part of the URI, before the : character.

std::string userinfo() const;
Returns the decoded userinfo part of this URI.

jsoncons::string_view encoded_userinfo() const noexcept;
Returns the encoded userinfo part of this URI.

jsoncons::string_view host() const noexcept;

jsoncons::string_view encoded_host() const noexcept;
Returns the host part of this URI.

jsoncons::string_view port() const noexcept;

jsoncons::string_view encoded_port() const noexcept;
Returns the port number of this URI.

std::string authority() const;
Returns the decoded authority part of this URI.

jsoncons::string_view encoded_authority() const noexcept;
Returns the encoded authority part of this URI.

std::string path() const;
Returns the decoded path part of this URI.

jsoncons::string_view encoded_path() const noexcept;
Returns the encoded path part of this URI.

std::string query() const;
Returns the decoded query part of this URI.

jsoncons::string_view encoded_query() const noexcept;

std::string query() const;

jsoncons::string_view encoded_query() const noexcept;
Returns the encoded query part of this URI.

std::string fragment() const;
Returns the decoded fragment part of this URI.

jsoncons::string_view encoded_fragment() const noexcept;
Returns the encoded fragment part of this URI.

bool is_absolute() const noexcept;
Returns true if this URI is absolute, false otherwise. An absolute URI is a URI that has
a scheme part (the part after the colon), e.g. 'https://john.doe@www.example.com'.

bool is_opaque() const noexcept;
Returns true if this URI is opaque, false otherwise. An opaque URI is an absolute URI whose
scheme-specific part does not begin with a slash character ('/'), e.g. 'mailto:john.doe@example.com'.

uri base() const noexcept;

uri resolve(const uri& base) const;

const std::string& string() const;

### Examples


4 changes: 0 additions & 4 deletions include/jsoncons/utility/uri.hpp
Original file line number Diff line number Diff line change
@@ -321,12 +321,8 @@ namespace jsoncons {

string_view host() const noexcept { return string_view(uri_string_.data()+host_.first,(host_.second-host_.first)); }

string_view encoded_host() const noexcept { return string_view(uri_string_.data()+host_.first,(host_.second-host_.first)); }

string_view port() const noexcept { return string_view(uri_string_.data()+port_.first,(port_.second-port_.first)); }

string_view encoded_port() const noexcept { return string_view(uri_string_.data()+port_.first,(port_.second-port_.first)); }

std::string authority() const
{
return decode_part(encoded_authority());
2 changes: 1 addition & 1 deletion include/jsoncons_ext/jsonschema/common/schema_builder.hpp
Original file line number Diff line number Diff line change
@@ -469,7 +469,7 @@ namespace jsonschema {
virtual std::unique_ptr<type_validator<Json>> make_type_validator(const compilation_context& context,
const Json& sch, const Json& parent)
{
std::string schema_location = context.get_base_uri().string();
uri schema_location = context.get_base_uri();
std::vector<json_schema_type> expected_types;

switch (sch.type())
2 changes: 1 addition & 1 deletion include/jsoncons_ext/jsonschema/common/uri_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ namespace jsonschema {
if (has_plain_name_fragment())
return *this;

jsoncons::jsonpointer::json_pointer pointer(std::string(uri_.encoded_fragment()));
jsoncons::jsonpointer::json_pointer pointer(std::string(uri_.fragment()));
pointer /= field;

jsoncons::uri new_uri(uri_, uri_fragment_part, pointer.to_string());
3 changes: 2 additions & 1 deletion include/jsoncons_ext/jsonschema/draft7/schema_builder_7.hpp
Original file line number Diff line number Diff line change
@@ -329,10 +329,11 @@ namespace draft7 {

for (const auto& prop : sch.object_range())
{
std::string sub_keys[] = {"patternProperties", prop.key()};
pattern_properties.emplace_back(
std::make_pair(
std::regex(prop.key(), std::regex::ECMAScript),
make_schema_validator(context, prop.value(), {}, anchor_dict)));
make_schema_validator(context, prop.value(), sub_keys, anchor_dict)));
}

return jsoncons::make_unique<pattern_properties_validator<Json>>(parent, std::move(schema_location),
4 changes: 2 additions & 2 deletions test/corelib/src/utility/uri_tests.cpp
Original file line number Diff line number Diff line change
@@ -370,8 +370,8 @@ TEST_CASE("uri parsing tests")
jsoncons::uri id = jsoncons::uri::parse(str, ec);

/*std::cout << "authority: [" << id.encoded_authority() << "]\n";
std::cout << "host: [" << id.encoded_host() << "]\n";
std::cout << "port: [" << id.encoded_port() << "]\n";
std::cout << "host: [" << id.host() << "]\n";
std::cout << "port: [" << id.port() << "]\n";
std::cout << "path: [" << id.encoded_path() << "]\n";
*/

Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@
}
},
"tests": [
/*{
{
"description": "non recognized members are ignored",
"data": { "answer 1": "42" },
"valid": true
@@ -114,7 +114,7 @@
"description": "regexes are case sensitive, 2",
"data": { "a_X_3": 3 },
"valid": false
}*/
}
]
},
{

0 comments on commit 151c917

Please sign in to comment.