Fix: update() parent pointers not updated after recursive merge with JSON_DIAGNOSTICS (#5187)
* added fix for issue 4813 Signed-off-by: VasuBhakt <cpswastik31@gmail.com> * added regression test for 4813 Signed-off-by: VasuBhakt <cpswastik31@gmail.com> * moved test from unit-regression2 to unit-diagnostics Signed-off-by: VasuBhakt <cpswastik31@gmail.com> --------- Signed-off-by: VasuBhakt <cpswastik31@gmail.com>
This commit is contained in:
1 parent
a69a42a930
commit
584e6b1cfb
3 files changed
+18
No files matched your search
@@ -3497,6 +3497,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
if (it2 != m_data.m_value.object->end())
|
if (it2 != m_data.m_value.object->end())
|
||||||
{
|
{
|
||||||
it2->second.update(it.value(), true);
|
it2->second.update(it.value(), true);
|
||||||
|
#if JSON_DIAGNOSTICS
|
||||||
|
it2->second.set_parents();
|
||||||
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24000,6 +24000,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
if (it2 != m_data.m_value.object->end())
|
if (it2 != m_data.m_value.object->end())
|
||||||
{
|
{
|
||||||
it2->second.update(it.value(), true);
|
it2->second.update(it.value(), true);
|
||||||
|
#if JSON_DIAGNOSTICS
|
||||||
|
it2->second.set_parents();
|
||||||
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,4 +262,16 @@ TEST_CASE("Regression tests for extended diagnostics")
|
|||||||
|
|
||||||
CHECK(k.dump() == "{\"prop1\":\"prop1_value\",\"root\":\"root_str\"}");
|
CHECK(k.dump() == "{\"prop1\":\"prop1_value\",\"root\":\"root_str\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Regression test for issue #4813 - update() with merge_objects=true triggers JSON_ASSERT with JSON_DIAGNOSTICS")
|
||||||
|
{
|
||||||
|
// https://github.com/nlohmann/json/issues/4813
|
||||||
|
nlohmann::ordered_json j1 = {{"numbers", {{"one", 1}}}};
|
||||||
|
nlohmann::ordered_json const j2 = {{"numbers", {{"two", 2}}}, {"string", "t"}};
|
||||||
|
CHECK_NOTHROW(j1.update(j2, true));
|
||||||
|
CHECK(j1["numbers"]["one"] == 1);
|
||||||
|
CHECK(j1["numbers"]["two"] == 2);
|
||||||
|
CHECK(j1["string"] == "t");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user