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

Unable to access invalid index: 1: invalid index referenced #178

Closed
wondywang opened this issue Jul 25, 2023 · 2 comments
Closed

Unable to access invalid index: 1: invalid index referenced #178

wondywang opened this issue Jul 25, 2023 · 2 comments

Comments

@wondywang
Copy link

wondywang commented Jul 25, 2023

Hey folks,

I discovered that we get a internal error if we apply the following operations to a JSON:

[
    {
        "op":"remove",
        "path":"/foo/1"
    },
    {
        "op":"remove",
        "path":"/foo/2"
    }
]

Test case:

func TestApply(t *testing.T) {
	patch := `[ { "op": "remove", "path": "/foo/1" },{ "op": "remove", "path": "/foo/2" } ]`
	doc := `{ "foo": [ "bar", "qux", "baz" ] }`
	patchObj, err := DecodePatch([]byte(patch))
	if err != nil {
		t.Errorf("unexpected error: %+v", err)
	}
	patchedJS, err := patchObj.Apply([]byte(doc))
	if err != nil {
		t.Errorf("patchObj.Apply internal error occurred, %v", err)
	}
	t.Logf("patchedJS: %s", patchedJS)
}

Output:

patchObj.Apply internal error occurred, error in remove for path: '/foo/2': Unable to access invalid index: 2: invalid index referenced

If multiple paths are removed, this exception will be reported.

@wondywang
Copy link
Author

it also mentioned here: mattbaird/jsonpatch#30

@wondywang
Copy link
Author

it also mentioned here: mattbaird/jsonpatch#30

In the latest version, the remove operation has been reversed.

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 a pull request may close this issue.

1 participant