From 9df99f402d07d4e1edfaadcdc563981720617f9b Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 16 Nov 2024 21:00:54 -0800 Subject: [PATCH 1/2] Fix #1361: handle non-escaping '~' correctly --- .../fasterxml/jackson/core/JsonPointer.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/core/JsonPointer.java b/src/main/java/com/fasterxml/jackson/core/JsonPointer.java index 0b95237d4b..6d33a9f394 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonPointer.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonPointer.java @@ -803,7 +803,7 @@ 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! @@ -811,7 +811,7 @@ protected static int _extractEscapedSegment(String input, int firstCharOffset, } ++i; if (c == ESC && i < end) { - _appendEscape(sb, input.charAt(i++)); + i += _appendEscape(sb, input.charAt(i)); continue; } sb.append(c); @@ -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() From 61bb187011c2c291ecccfb3242b54deebd12e6e6 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 16 Nov 2024 21:07:38 -0800 Subject: [PATCH 2/2] Update release notes --- release-notes/VERSION-2.x | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 49430cfff3..9252f89e9e 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -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)