Skip to content

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

@jankeromnes

Description

@jankeromnes

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions