Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation: jsonpatch.applyPatch() accepts "patches" that are Objects but not Arrays #186

Closed
jankeromnes opened this issue Jul 17, 2017 · 3 comments

Comments

@jankeromnes
Copy link

jankeromnes commented Jul 17, 2017

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?

@alshakero
Copy link
Collaborator

Hi! Thank you and I agree, we should error when this happens. Will look at it soon.

@alshakero
Copy link
Collaborator

Released 2.0.4. Thank you so much @jankeromnes.

@jankeromnes
Copy link
Author

My pleasure! Thanks for fixing it so quickly 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants