Starcounter-Jack / JSON-Patch

Lean and mean Javascript implementation of the JSON-Patch standard (RFC 6902). Update JSON documents using delta patches.
MIT License
1.79k stars 215 forks source link

comparing property with a tilde generates incorrect patch path #241

Closed acidduckling closed 4 years ago

acidduckling commented 4 years ago

Hello,

I believe I have found a bug when generating the path for an object that has a tilde (~) in an object property. An index seems to be appended to the tilde in the path string for some reason.

Here is a small snippet which produces the issue:

const obj1 = { 'my~id': { name: 'value1' } };
const obj2 = { 'my~id': { name: 'value1 - renamed' } };
const patch = jsonPatch.compare(obj1, obj2);
console.log(patch);

The actual output is: "[{"op":"replace","path":"/my~0id/name","value":"value1 - renamed"}]"

The expected output would be: "[{"op":"replace","path":"/my~id/name","value":"value1 - renamed"}]"

EDIT: I can reproduce this problem in Chrome (78.0.3904.108), and running directly in Node 10.16

Cheers, Clay.

acidduckling commented 4 years ago

I've just realised that the tilde is part of the RFC for JSON Patch:

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

So it looks like this is expected behaviour! I will just close this ticket.