Giter Club home page Giter Club logo

json_diff_rfc6902's People

Contributors

caohanyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

nlac

json_diff_rfc6902's Issues

crash when property is undefined

const { diff } = require('json-diff-rfc6902');

const before = {
    a: 'text',
}
const after = {
    a: 'text',
    b: undefined
};

diff(before, after);

crashes with

.\node_modules\json-diff-rfc6902\lib\unchangedArea.js:71
    if (newValue.toString() === value) {
                ^

TypeError: Cannot read property 'toString' of undefined
    at Object.findValueInUnchanged (.\node_modules\json-diff-rfc6902\lib\unchangedArea.js:71:17)
    at generateObjectDiff (.\node_modules\json-diff-rfc6902\JSON-Diff.js:127:35)
    at generateDiff (.\node_modules\json-diff-rfc6902\JSON-Diff.js:51:5)
    at diff (.\node_modules\json-diff-rfc6902\JSON-Diff.js:33:3)

bug in the "move" op on array

How to reproduce:
var obj = [ "thisisbad", { choices: [ { choices: [] } ] } ]; jdr.apply(obj, [{ op: "move", from: "/0", path: "/0/choices/0/choices/0" }]);

Result: Uncaught TypeError: Cannot read property '0' of undefined

Expected result:
[ { "choices": [ { "choices": [ "thisisbad" ] } ] } ]

Excellent lib, just a feature request

Hi,
first let me thank you for this one, it generates the most clever diffs among all the similar libs i checked. As an extra, it is able to apply patches.
Please consider to implement a "public" get(object, path) method that calculates JSON Pointer, so this lib will cover all basic features people need when working with JSON patches.

diff calculated wrong

In the simple example, a weird "copy" patch is calculated as a diff what is wrong. Check it on codepen or here:

var a = {
  choices: [
    {id: "2"}
  ]
};
var b = {
  choices: [
    {id: "2"}
  ],
  description: "2"
};

var diff = jdr.diff(a, b);
jdr.apply(a, diff, {OBJ_COM:false});

console.info("diff:", diff); // results [{op: "copy", path: "/description", from: "/choices/0"}]
console.info("this should be b:", a); // results something else than b

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.