Steps to reproduce:
try {
jsonpatch.applyPatch({ a: 5 }, /* patch = */ { content: 'Invalid patch' }, /* validateOperation = */ true);
} catch (error) {
console.error('Something went wrong:', error);
}
- Expected behavior: An error is thrown (something like "Invalid JSON Patch").
- Actual observed behavior: No error is thrown (just like if
patch was an empty Array).
In the applyPatch implementation, we can see that if patch is an object like {} instead of an Array of valid JSON Patch operations, it will get "applied" successfully (because patch.length will be undefined, and the for-loop won't run).
Maybe it should throw if validateOperation is true?