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

Nested array issue #261

Closed
andysCaplin opened this issue Jul 16, 2020 · 6 comments
Closed

Nested array issue #261

andysCaplin opened this issue Jul 16, 2020 · 6 comments

Comments

@andysCaplin
Copy link

Describe the bug
Enumerate the steps to reproduce the bug
Include a small, self-contained example if possible

Given a json document with a nested array value 'names', e.g.

{ "names" : [ "a", "b", "c", "d" ] }
We've noticed that when the document is updated to remove entries in the nested array, for example when removing "c" and "d" above, we're sent a patchDocument that has the following operations:

OperationType:Remove path:"/names/2"
OperationType:Remove path:"/names/3"

This fails as /names/3 is no longer present once 2 is removed.

According to https://tools.ietf.org/html/rfc6902 it should instead read:

OperationType:Remove path:"/names/2"
OperationType:Remove path:"/names/2"

In https://tools.ietf.org/html/rfc6902 it states

Operations are applied sequentially in the order they
appear in the array. Each operation in the sequence is applied to
the target document; the resulting document becomes the target of the
next operation. Evaluation continues until all operations are
successfully applied or until an error condition is encountered.

What compiler, architecture, and operating system?

RedHat Linux 64 bit

What jsoncons library version?

0.153.3

@danielaparker
Copy link
Owner

danielaparker commented Jul 16, 2020

I believe jsonpatch::apply_patch works correctly. In your example, the patch should be

[
    {
        "op": "remove",
        "path": "/names/3"
    },
    {
        "op": "remove",
        "path": "/names/2"
    }
]

and applying that patch to the source document does give

{
    "names": ["a", "b"]
}

However, it looks like there is a bug in the function json_patch::from_diff that creates a patch from a source and target document. It looks like it is generating the remove statements in the wrong order.

Daniel

@andysCaplin
Copy link
Author

Hi - yes sorry. I transcribed the issue and didn't describe it fully. The remove operations mentioned above are being generated by jsoncons in that order when we apply a patch that removes 2 elements.

@danielaparker
Copy link
Owner

danielaparker commented Jul 16, 2020

The issue with jsonpatch::from_diff should be fixed on master. Thanks very much for reporting this. I've added your test to the test cases.

@andysCaplin
Copy link
Author

Thanks for the quick fix - when is the next release ?

@danielaparker
Copy link
Owner

We'll put this into patch release 0.154.2, should be out today or tomorrow.

@danielaparker
Copy link
Owner

Go with latest 0.154.3, not .2

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

No branches or pull requests

2 participants