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

Fix JsonPatch move operation on arrays #322

Merged
merged 4 commits into from Aug 20, 2022

Conversation

z4kn4fein
Copy link
Contributor

@z4kn4fein z4kn4fein commented Aug 19, 2022

Hi there!

I've captured an issue with the move JsonPatch operation that causes the following:

  • Given the following source data:
    {
     "items": [
         {
             "value": 1
         },
         {
             "value": 2
         },
         {
             "value": 3
         },
         {
             "value": 4
         }
      ]
    }
    
  • Patched with the following op:
    [{
        "op": "move",
        "path": "/items/0",
        "from": "/items/1"
    }]
    
  • Gives the following result:
    {
      "items": [
        {
          "value": 2
        },
        {
          "value": 3
        },
        {
          "value": 4
        }
      ]
    }
    

I've just noticed that around v2.0.0, an array Insert() operation was changed to an indexed write, causing this "deleting shift" effect. I switched back to Insert() and added unit tests to cover my changes. Let me know if I should do anything differently. Thanks!

@gregsdennis
Copy link
Owner

Thanks for this. I'll investigate the change you mentioned in 2.0.0 to find out why that occurred. I think this change is good.

@gregsdennis
Copy link
Owner

Yeah, I'm not sure where the bug was introduced, but you're right about the behavior. I'll set up a release branch and have this pushed out soon.

Thanks again.

@gregsdennis gregsdennis changed the base branch from master to patch-2.0.4 August 20, 2022 06:28
@gregsdennis gregsdennis merged commit d2366f0 into gregsdennis:patch-2.0.4 Aug 20, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants