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

Handle additional, common edge case in path resolution logic #246

Closed jaylattice closed 4 years ago

jaylattice commented 4 years ago

Hello. First, thanks a bunch for making this library!! I think you may have seen my previous PR where I mentioned wanting to fix a certain unhandled edge case in this library. This is the fix!

The problem is that we aren't detecting when a specified path attempts to index too far into a document. Please see the tests I added which act as documentation for this behavior. Previously, both of those edge cases were throwing TypeErrors. Now, those edge cases will throw a more intuitive error: OPERATION_PATH_UNRESOLVABLE.

I've also included the broken test script fix in this PR. Thanks again!