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

Strange behaviour! If path don't start with '/' #77

Closed
knde opened this issue Aug 18, 2015 · 4 comments
Closed

Strange behaviour! If path don't start with '/' #77

knde opened this issue Aug 18, 2015 · 4 comments
Labels

Comments

@knde
Copy link

knde commented Aug 18, 2015

var obj = {firstName: "Albert"};
var patches = [{op: "add", path: "/lastName", value:"Wester"}];
jsonpatch.apply(obj,patches);
obj = {firstName: 'Albert' },lastName:'Wester' }
If path = "lastName"
The result
{ '0': 'W', '1': 'e', '2': 's', '3': 't', '4': 'e', '5': 'r' }

why?

@warpech
Copy link
Collaborator

warpech commented Aug 18, 2015

Hi! This is because it is not a correct path and code is optimized for speed, not for validating patches.

To turn on validation, use true as the third parameter (jsonpatch.apply(obj, patches, true);)

Check out https://tools.ietf.org/html/rfc6901 for the spec of the path value.

@warpech warpech closed this as completed Aug 18, 2015
@warpech
Copy link
Collaborator

warpech commented Aug 18, 2015

Oops! Just noticed that such path does not raise an error with validation. Reopening this for fixing

@warpech warpech reopened this Aug 18, 2015
@warpech warpech added the bug label Aug 23, 2015
tomalec added a commit that referenced this issue Sep 26, 2016
Adding validation for paths starting with "/". Fixes issue #77.
@MarkHerhold
Copy link
Contributor

@tomalec This can be closed now. Please do a patch release when you have time! Thanks! 👍

@tomalec
Copy link
Collaborator

tomalec commented Sep 26, 2016

Thanks @MarkHerhold for support :)
1.1.1 released.

@tomalec tomalec closed this as completed Sep 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants