Escape ~ and / in JSONPointer.toURIFragment()

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 #1082
This commit is contained in:
Denys Khalitov
2026-09-26 17:19:47 +03:00
parent b55c69e650
commit f875ab2fc7
2 changed files with 23 additions and 3 deletions
+1 -1
View File
@@ -276,7 +276,7 @@ public class JSONPointer {
try {
StringBuilder rval = new StringBuilder("#");
for (String token : this.refTokens) {
rval.append('/').append(URLEncoder.encode(token, ENCODING));
rval.append('/').append(URLEncoder.encode(escape(token), ENCODING));
}
return rval.toString();
} catch (UnsupportedEncodingException e) {