Skip to content

Commit

Permalink
Fix #1361: handle non-escaping '~' more correctly (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Nov 18, 2024
1 parent 22499ed commit 0bee790
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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

0 comments on commit 0bee790

Please sign in to comment.