mirror of
https://github.com/nlohmann/json.git
synced 2026-10-28 00:35:43 +00:00
Detect a patch stored inside the patched value with JSON_DIAGNOSTICS
patch_inplace applied a copy only when the patch was the value itself. With JSON_DIAGNOSTICS the parent pointers make it cheap to also detect a patch nested inside the value, so that case is handled the same way. Without diagnostics it stays documented undefined behavior. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
4 files changed
+41
-8
No files matched your search
@@ -855,6 +855,19 @@ TEST_CASE("JSON patch")
|
||||
CHECK(doc == expected_copies);
|
||||
}
|
||||
|
||||
#if JSON_DIAGNOSTICS
|
||||
SECTION("patch stored inside the patched value")
|
||||
{
|
||||
// the parent pointers of JSON_DIAGNOSTICS make the aliasing detectable
|
||||
const json op = {{"op", "replace"}, {"path", "/patch"}, {"value", 1}};
|
||||
json doc = {{"a", 1}, {"patch", json::array({op})}};
|
||||
const json expected = doc.patch(doc["patch"]);
|
||||
|
||||
doc.patch_inplace(doc["patch"]);
|
||||
CHECK(doc == expected);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("copy operations with spare capacity")
|
||||
{
|
||||
// reserve while the array is empty: reallocating non-empty
|
||||
|
||||
Reference in new issue
Block a user