bruth / jsonpatch-js

A JavaScript implementation of the JSON Media Type for partial modifications: http://tools.ietf.org/html/rfc6902
http://bruth.github.io/jsonpatch-js
BSD 2-Clause "Simplified" License
181 stars 24 forks source link

Does not correctly apply "test" ops #14

Closed gobengo closed 10 years ago

gobengo commented 10 years ago

Appendix A.14 of the spec specifies that the result of applying a "test" op should be the input JSON document, not a non-JSON raw Boolean.

However, as the README states and this lib behaves, if the last op in a JSONPatch document is a test, the result of require('json-patch').apply(ops, in) is a Boolean.

This script should succeed without error, but throws an AssertionError for the above reason.

var jsonPatch = require('json-patch');
var assert = require('chai').assert;

// Testing http://tools.ietf.org/html/rfc6902#appendix-A.14

var exampleTarget = {
  "/": 9,
  "~1": 10
};

var patch = [
  { "op": "test", "path": "/~01", "value": 10 }
];

var expectedResult = {
  "/": 9,
  "~1": 10
};

assert.deepEqual(jsonPatch.apply(exampleTarget, patch), expectedResult);
gobengo commented 10 years ago

FWIW these other libs pass the above test https://github.com/cujojs/jiff https://www.npmjs.org/package/jsonpatch

bruth commented 10 years ago

0.5.0 Released

bruth commented 10 years ago

Thank you for opening the issue.