Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in diff function #2054

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7930,7 +7930,7 @@ class basic_json
result.push_back(
{
{"op", "add"},
{"path", path + "/" + std::to_string(i)},
{"path", path + "/-"},
{"value", target[i]}
});
++i;
Expand Down
2 changes: 1 addition & 1 deletion single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22741,7 +22741,7 @@ class basic_json
result.push_back(
{
{"op", "add"},
{"path", path + "/" + std::to_string(i)},
{"path", path + "/-"},
{"value", target[i]}
});
++i;
Expand Down
8 changes: 8 additions & 0 deletions test/src/unit-regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)
Expand Down