JSON-Patch icon indicating copy to clipboard operation
JSON-Patch copied to clipboard

replace incorrectly adds value when target location does not exist

Open rybesh opened this issue 4 years ago • 0 comments

Section 4.3 of RFC6902 says:

The target location MUST exist for the operation to be successful.

But fast-json-patch incorrectly does an add instead of failing in this situation:

var fastJsonPatch = require("fast-json-patch")
var document = { foo: "bar" };
var patch = [
  { op: "replace", path: "/biz", value: "baz" },
];
document = fastJsonPatch.applyPatch(document, patch).newDocument;

The result is:

{biz: "baz", foo: "bar"}

rybesh avatar Feb 18 '21 01:02 rybesh