Merge pull request #2054 from nlohmann/feature/issue1983

Fix bug in diff function
This commit is contained in:
Niels Lohmann authored and GitHub committed 2020-04-20 19:44:35 +02:00
commit a29e3b1318
3 files changed
+10 -2

No files matched your search

+1 -1
View File
@@ -8347,7 +8347,7 @@ class basic_json
result.push_back( result.push_back(
{ {
{"op", "add"}, {"op", "add"},
{"path", path + "/" + std::to_string(i)}, {"path", path + "/-"},
{"value", target[i]} {"value", target[i]}
}); });
++i; ++i;
+1 -1
View File
@@ -23833,7 +23833,7 @@ class basic_json
result.push_back( result.push_back(
{ {
{"op", "add"}, {"op", "add"},
{"path", path + "/" + std::to_string(i)}, {"path", path + "/-"},
{"value", target[i]} {"value", target[i]}
}); });
++i; ++i;
+8
View File
@@ -1896,6 +1896,14 @@ TEST_CASE("regression tests")
static_assert(!std::is_constructible<json, std::tuple<NotSerializableData, std::string>>::value, ""); static_assert(!std::is_constructible<json, std::tuple<NotSerializableData, std::string>>::value, "");
static_assert(std::is_constructible<json, std::tuple<int, std::string>>::value, ""); static_assert(std::is_constructible<json, std::tuple<int, std::string>>::value, "");
} }
SECTION("issue #1983 - JSON patch diff for op=add formation is not as per standard (RFC 6902)")
{
const auto source = R"({ "foo": [ "1", "2" ] })"_json;
const auto target = R"({"foo": [ "1", "2", "3" ]})"_json;
const auto result = json::diff(source, target);
CHECK(result.dump() == R"([{"op":"add","path":"/foo/-","value":"3"}])");
}
} }
#if not defined(JSON_NOEXCEPTION) #if not defined(JSON_NOEXCEPTION)