Undocumented behavior: jsonpatch.compare alters obj1
The compare function calls _generate internally, which, in addition to generating a patches array, updates the mirror object to match the obj object! This caught me by surprise and created a bunch of hard-to-debug problems.
Please document this behavior in the API docs, or better yet, allow this behavior to be disabled (since now I have to make lots of deep clones every time I call jsonpatch.compare to keep it from messing with my program state...)
cc @tomalec, @Starcounter-Jack
Thanks for pointing that!
I would said that from API purity perspective we should not update mirror object on every (public) compare call, maybe unless explicitly specified.
I think we may consider, if possible, adding a parameter for that.
Agreed.
Actually we addressed this problem before (there was a PR: https://github.com/Starcounter-Jack/JSON-Patch/pull/53), so that sounds like a regression.
There is even a test for that: https://github.com/Starcounter-Jack/JSON-Patch/commit/b2435fa725a2a4efc7eb7b7059ddf5fa4c344771#diff-2f9a66403e6f581b7b3abaff2c80ca45R694. Maybe the test is too naive.
Isn't this fixed by https://github.com/Starcounter-Jack/JSON-Patch/pull/167?
Looking at just code, I'm not so sure https://github.com/Starcounter-Jack/JSON-Patch/pull/167/files#diff-2b195b8e1323c973a44eefb88a63a5c7R778 does not clone.