diff-json icon indicating copy to clipboard operation
diff-json copied to clipboard

Fails for case of newly added property with a value of null

Open zwilliam88 opened this issue 7 years ago • 5 comments

A simple test case:

    it 'should properly handle new null property', ->
      before = {}
      after = { newProp: null }
      changesets.applyChanges before, changesets.diff before, after
      expect(after).to.eql before

Fails with "TypeError: Cannot read property 'length' of undefined"

https://github.com/viruschidai/diff-json/blob/4356e69d6755f3cfa7a2396e33b28a8797a834b0/src/changesets.coffee#L212

should probably be:

      if !change.changes

In its current form applyChanges calls applyBranchChanges for the add of a new property with a value of null. applyBranchChanges expects a changes array to exist on the change and calls length on undefined.

zwilliam88 avatar Aug 31 '17 00:08 zwilliam88

Yep, this happens :( Any expected fix?

diego-palla avatar May 09 '19 14:05 diego-palla

Anyone wants to PR?

viruschidai avatar May 13 '19 11:05 viruschidai

Shit, I just wasted a lot of time before checking the issues here 🤦

Wonder why this hasn't been picked up in two years @viruschidai? But happy to find a solution.

0x80 avatar May 07 '20 16:05 0x80

#20

In the meantime you can do something like: yarn add https://github.com/0x80/diff-json\#topic/fix-newly-added-null

0x80 avatar May 07 '20 16:05 0x80

@viruschidai Could you please release v2.0.1 with this fix?

I waited a year before you merged the PR in April, but there has been no new release so I still can't use normal npm version control for this library.

0x80 avatar Sep 04 '21 14:09 0x80