wbish / jsondiffpatch.net

JSON object diffs and reversible patching (jsondiffpatch compatible)
MIT License
370 stars 83 forks source link

`~` and `/` show be replaced in patch path #45

Open moonheart opened 4 years ago

moonheart commented 4 years ago

As rfc6901#section-3 documented, we should replace ~ with ~0 and replace / with ~1.

This is Also the problem I encounted when trying to patch k8s resources, error message: the server rejected our request due to an error in our request.

Json Patch

A JSON Pointer is a Unicode string (see [RFC4627], Section 3) containing a sequence of zero or more reference tokens, each prefixed by a '/' (%x2F) character.

Because the characters '\~' (%x7E) and '/' (%x2F) have special meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/' needs to be encoded as '~1' when these characters appear in a reference token.

shochwald-maptek commented 3 years ago

Agreed, this is causing a bug in my use case where users legitimately enter values including a '/'.