Escape ~ and / in JSONPointer.toURIFragment() - #1083
DarkLight606 wants to merge 1 commit into
Conversation
toURIFragment() URL-encoded each reference token but skipped the ~0/~1 escaping from RFC 6901. Tokens are stored as literal key names, so a key containing / or ~ produced a fragment that parsed back to a different pointer. Apply escape() before encoding, as toString() already does. Fixes stleary#1082
|
|
What problem does this code solve? Risks Changes to the Existing Behavior Changes to the API Will this require a new release? Should the documentation be updated? Unit Tests Refactoring Review status Starting 3-day comment window |



Fixes #1082.
toURIFragment() now applies the RFC 6901 escaping (~ to ~0, / to ~1) to each token before URL-encoding it, matching what toString() does. Before this, a pointer to the key "/" became "#/%2F", which the constructor decodes and splits into two empty tokens, and a pointer to "~1" came back as a pointer to "/".
Tests: added toURIFragmentEscaping and toURIFragmentRoundTrip. The existing toURIFragment assertion for "/m~n" changes from "#/m%7En" to "#/m%7E0n", since the old value was the unescaped form.
mvn clean test passes on JDK 8 and 11.