cujojs / jiff

JSON Patch and diff based on rfc6902
Other
627 stars 41 forks source link

fix array replace #35

Closed ppaskaris closed 7 years ago

ppaskaris commented 8 years ago

This fixes the feature whereby an add op followed immediately by a remove op are coalesced into a replace op.

Consider Jiff.diff(["a", "b", "c"], ["a", "b", "z"]);

Before this fix:

[
  {
    "op": "add",
    "path": "/2",
    "value": "z"
  },
  {
    "op": "test",
    "path": "/3",
    "value": "c"
  },
  {
    "op": "remove",
    "path": "/3"
  }
]

After this fix:

[
  {
    "op": "test",
    "path": "/2",
    "value": "c"
  },
  {
    "op": "replace",
    "path": "/2",
    "value": "z"
  }
]
briancavalier commented 8 years ago

Hi @ppaskaris, thanks! I'll have time within the next day or so to look at this.