json-patch icon indicating copy to clipboard operation
json-patch copied to clipboard

EnsurePathExistsOnAdd not working with escaped slash

Open LorenzBischof opened this issue 2 months ago • 0 comments

When escaping a slash with ~1 the following error is printed when trying to add a nested path and using ensurePathExistsOnAdd:

patch_test.go:831: Unable to apply patch: add operation does not apply: doc is missing path: "/with~1slash/nested": missing value

The first test works, the second one fails:

        {
                `{ "foo": ["bar"]}`,
                `[ { "op": "add", "path": "/with~1slash", "value": "bar" } ]`,
                `{ "foo": ["bar"], "with/slash": "bar"}`,
                true,
                true,
        },
        {
                `{ "foo": ["bar"]}`,
                `[ { "op": "add", "path": "/with~1slash/nested", "value": "bar" } ]`,
                `{ "foo": ["bar"], "with/slash": { "nested": "bar"}}`,
                true,
                true,
        },

LorenzBischof avatar Nov 20 '25 13:11 LorenzBischof