Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1361: handle non-escaping '~' more correctly #1362

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ a pure JSON library.
#1356: Make `JsonGenerator::writeTypePrefix` method to not write a
`WRAPPER_ARRAY` when `typeIdDef.id == null`
(contributed by Eduard G)
#1361: `JsonPointer` parsing of '~' not followed by "0" or "1" unexpected
(reported by @slz30)

2.18.1 (28-Oct-2024)

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/fasterxml/jackson/core/JsonPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,15 +803,15 @@ protected static int _extractEscapedSegment(String input, int firstCharOffset,
if (toCopy > 0) {
sb.append(input, firstCharOffset, i-1);
}
_appendEscape(sb, input.charAt(i++));
i += _appendEscape(sb, input.charAt(i));
while (i < end) {
char c = input.charAt(i);
if (c == SEPARATOR) { // end is nigh!
return i;
}
++i;
if (c == ESC && i < end) {
_appendEscape(sb, input.charAt(i++));
i += _appendEscape(sb, input.charAt(i));
continue;
}
sb.append(c);
Expand All @@ -820,15 +820,18 @@ protected static int _extractEscapedSegment(String input, int firstCharOffset,
return -1;
}

private static void _appendEscape(StringBuilder sb, char c) {
private static int _appendEscape(StringBuilder sb, char c) {
if (c == '0') {
c = ESC;
} else if (c == '1') {
c = SEPARATOR;
} else {
sb.append(ESC);
return 1;
}
sb.append(c);
if (c == '1') {
sb.append(SEPARATOR);
return 1;
}
// Not a valid escape; just output tilde, do not advance past following char
sb.append(ESC);
return 0;
}

protected JsonPointer _constructHead()
Expand Down