mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 06:14:59 +01:00
Do not throw in contains() for an empty array reference token
json_pointer::contains() rejected malformed array indices, but an empty reference token (e.g. "/a/" where "a" is an array, or "/" on an array) passed every check and reached array_index(), which throws out_of_range.404. contains() must not throw (cf. #5395), so it now returns false for an empty token. at() still throws out_of_range.404. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -19588,6 +19588,12 @@ class json_pointer
|
||||
// "-" always fails the range check
|
||||
return false;
|
||||
}
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token.empty()))
|
||||
{
|
||||
// an empty reference token is not an array index; array_index()
|
||||
// would throw out_of_range.404 -- contains() must not throw (see #5395)
|
||||
return false;
|
||||
}
|
||||
if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9")))
|
||||
{
|
||||
// invalid char
|
||||
|
||||
Reference in New Issue
Block a user