Skip to content

Unescape ~1 before ~0 in JSON pointers - #38

Merged
corka149 merged 1 commit into
corka149:masterfrom
bardrop-oss:fix-unescape-order
Nov 30, 2026
Merged

corka149 merged 1 commit into
corka149:masterfrom
bardrop-oss:fix-unescape-order

Conversation

@bardrop

@bardrop bardrop commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

unescape/1 replaced ~0 before ~1, so ~01 became ~1 and then /. RFC 6901 asks for the other order: "first transforming any occurrence of the sequence '~1' to '/', and then [...] '0' to ''" (section 4).

A patch made by diff/2 can fail to apply because of it:

source = %{"~1" => 1}
patch = Jsonpatch.diff(source, %{"~1" => 2})
# [%{op: "replace", path: "/~01", value: 2}]
Jsonpatch.apply_patch(patch, source)
# {:error, %Jsonpatch.Error{reason: {:invalid_path, ["/"]}, ...}}

With "add" the value ends up under the key "/". The two new checks fail without the change.

@corka149 corka149 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi again, nice catch. Lgtm

@corka149
corka149 merged commit 5033124 into corka149:master Nov 30, 2026
4 checks passed
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.

2 participants