1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

Fix patch::add creating nonexistent parents (#3628)

* Fix patch::add creating nonexistent parents

The previous behavior was not in accordance with RFC6902.
Add unit test.

Fixes #3134.

* Fix incorrect JSON patch unit test

Co-authored-by: Hudson00 <yagdhscdasg@gmail.com>
This commit is contained in:
Florian Albrechtskirchinger
2022-07-30 21:23:55 +02:00
committed by GitHub
parent d1d79b930d
commit fca1ddda96
3 changed files with 19 additions and 9 deletions

View File

@ -4683,7 +4683,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// get reference to parent of JSON pointer ptr
const auto last_path = ptr.back();
ptr.pop_back();
basic_json& parent = result[ptr];
// parent must exist when performing patch add per RFC6902 specs
basic_json& parent = result.at(ptr);
switch (parent.m_type)
{