Skip to content

move fails with "missing value" if from is "" #192

Closed

Description

@lucastheisen

According to the JSON Pointer RFC 6901:

The following JSON strings evaluate to the accompanying values:

""           // the whole document

But using that as a from results in a missing value error.

Adding this test will demonstrate the bug:

func TestMoveFromRoot(t *testing.T) {
	expected := `{"baz":{"foo":"bar"}}`
	res, err := applyPatch(`{"foo":"bar"}`, `[{"op":"move","from":"","path":"/baz"}]`)
	if err != nil {
		t.Errorf("unexpected error: %+v", err)
	} else if res != expected {
		t.Errorf("expected:\n%s\ngot:\n%s", expected, res)
	}
}

Activity

  1. lucastheisen commented on Jan 3, 2024

    @lucastheisen
    Author

    Well, i just saw this in the RFC for JSON Patch:

    The "from" location MUST NOT be a proper prefix of the "path"
    location; i.e., a location cannot be moved into one of its children.

    So my use case is invalid (as is the test per-se)... But the lack of support for "" JSON Pointer may still be something you want to address. You can close this issue out if you would like, or modify it to deal with the JSON Pointer support.

  2. evanphx commented on Jan 11, 2024

    @evanphx
    Owner

    @lucastheisen Gotcha gotcha. Trying some other json patch implementations, they largely fail to handle when from is "", so I think we're in a bit of uncharted waters here.

  3. added a commit that references this issue on Jan 11, 2024
    01d25e9
  4. evanphx commented on Jan 11, 2024

    @evanphx
    Owner

    Could you have a look at #193 and give me your thoughts? Thanks!

  5. added a commit that references this issue on Jan 12, 2024
    b5e20d4
  6. added a commit that references this issue on Jan 12, 2024
    a9c085a
  7. lucastheisen commented on Jan 12, 2024

    @lucastheisen
    Author

    @evanphx , that merge looks great.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions