Compare commits

..
Author SHA1 Message Date
Niels Lohmann 93011250d3 json_view: pointer tokens that cannot be array indices create objects
editable_document::set() chose an array for a null parent whenever the
token consisted of digits, so "01" threw parse_error.106 and the empty
token threw, while basic_json::operator[](json_pointer) has created an
object for such tokens since #5358. This broke
unit-json_view_edit_values on develop. Use the same RFC 6901 array index
test as basic_json.

Also re-indent the unflatten test that the astyle check flagged.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-26 22:21:17 +01:00
2 changed files with 12 additions and 4 deletions

No files matched your search

+6 -2
View File
@@ -1313,7 +1313,7 @@ class basic_json_document
/// member is set (added if missing), an array element assigned, and "-"
/// or the size of the array appends. A null parent becomes what
/// basic_json's operator[](json_pointer) makes of it: an array for "-"
/// and for digits (padded with nulls up to the index), an object otherwise.
/// and for array indices (padded with nulls up to the index), an object otherwise.
template<typename V>
view_type set(const json_pointer& ptr, V&& value)
{
@@ -1329,7 +1329,11 @@ class basic_json_document
{
return push_back(parent, std::forward<V>(value));
}
const bool digits = std::all_of(token.begin(), token.end(), [](const char c)
// (a token that cannot be an array index, such as "01" or "", names an
// object member, as in basic_json)
const bool digits = !token.empty()
&& (token.size() == 1 || token[0] != '0')
&& std::all_of(token.begin(), token.end(), [](const char c)
{
return c >= '0' && c <= '9';
});
+6 -2
View File
@@ -9067,7 +9067,7 @@ class basic_json_document
/// member is set (added if missing), an array element assigned, and "-"
/// or the size of the array appends. A null parent becomes what
/// basic_json's operator[](json_pointer) makes of it: an array for "-"
/// and for digits (padded with nulls up to the index), an object otherwise.
/// and for array indices (padded with nulls up to the index), an object otherwise.
template<typename V>
view_type set(const json_pointer& ptr, V&& value)
{
@@ -9083,7 +9083,11 @@ class basic_json_document
{
return push_back(parent, std::forward<V>(value));
}
const bool digits = std::all_of(token.begin(), token.end(), [](const char c)
// (a token that cannot be an array index, such as "01" or "", names an
// object member, as in basic_json)
const bool digits = !token.empty()
&& (token.size() == 1 || token[0] != '0')
&& std::all_of(token.begin(), token.end(), [](const char c)
{
return c >= '0' && c <= '9';
});