diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 63df1a63b4..79b56d07ec 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -862,6 +862,21 @@ TEST_CASE("regression tests 2") CHECK(a2.type() == typeid(j)); } #endif + + SECTION("issue #3134 - Applying JSON patch creates parent object") + { + json doc = R"({ + "a": {} + })"_json; + json patch = R"([{ + "op": "add", + "path": "/a/b/c", + "value": 1 + }])"_json; + + // patch should cause an error because "b" does not exist in doc + CHECK_THROWS_WITH_AS(doc.patch(patch), "[json.exception.out_of_range.403] key 'b' not found", json::out_of_range&); + } } DOCTEST_CLANG_SUPPRESS_WARNING_POP