Skip to content

Commit 40af3ec

Browse files
BalrogOfHellpboettch
authored andcommitted
Reference validation using contains() result rather than exception handling
1 parent 8edd521 commit 40af3ec

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/json-validator.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ class root_schema
254254
//
255255
// an unknown keyword can only be referenced by a json-pointer,
256256
// not by a plain name fragment
257-
if (uri.pointer().to_string() != "") {
258-
try {
259-
auto &subschema = file.unknown_keywords.at(uri.pointer()); // null is returned if not existing
260-
auto s = schema::make(subschema, this, {}, {{uri}}); // A JSON Schema MUST be an object or a boolean.
261-
if (s) { // nullptr if invalid schema, e.g. null
257+
if (!uri.pointer().to_string().empty()) {
258+
bool contains_pointer = file.unknown_keywords.contains(uri.pointer());
259+
if (contains_pointer) {
260+
auto &subschema = file.unknown_keywords.at(uri.pointer());
261+
auto s = schema::make(subschema, this, {}, {{uri}});
262+
if (s) { // if schema is valid (non-null)
262263
file.unknown_keywords.erase(uri.fragment());
263264
return s;
264265
}
265-
} catch (nlohmann::detail::out_of_range &) { // at() did not find it
266266
}
267267
}
268268

0 commit comments

Comments
 (0)