Skip to content

Commit f9f568a

Browse files
committed
Merge branch '2.13' into 2.14
2 parents 533e2f0 + 0fbb529 commit f9f568a

File tree

5 files changed

+78
-12
lines changed

5 files changed

+78
-12
lines changed

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ JSON library.
1818

1919
No changes since 2.13
2020

21+
2.13.1 (not yet released)
22+
23+
#713: Incorrect parsing of single-quoted surrounded String values containing double quotes
24+
(reported by wcarmon@github)
25+
2126
2.13.0 (30-Sep-2021)
2227

2328
#652: Misleading exception for input source when processing byte buffer

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -2022,10 +2022,9 @@ protected JsonToken _handleApos() throws IOException
20222022
int i = (int) c;
20232023
if (i <= '\\') {
20242024
if (i == '\\') {
2025-
/* Although chars outside of BMP are to be escaped as
2026-
* an UTF-16 surrogate pair, does that affect decoding?
2027-
* For now let's assume it does not.
2028-
*/
2025+
// Although chars outside of BMP are to be escaped as
2026+
// an UTF-16 surrogate pair, does that affect decoding?
2027+
// For now let's assume it does not.
20292028
c = _decodeEscaped();
20302029
} else if (i <= '\'') {
20312030
if (i == '\'') {

src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,10 @@ protected JsonToken _handleApos() throws IOException
21522152
if (c == '\'') {
21532153
break main_loop;
21542154
}
2155-
if (codes[c] != 0) {
2155+
if ((codes[c] != 0)
2156+
// 13-Oct-2021, tatu: [core#721] Alas, regular quote is included as
2157+
// special, need to ignore here
2158+
&& (c != INT_QUOTE)) {
21562159
break ascii_loop;
21572160
}
21582161
outBuf[outPtr++] = (char) c;

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ protected String _parseAposName() throws IOException
21802180
break;
21812181
}
21822182
// additional check to skip handling of double-quotes
2183-
if ((codes[ch] != 0) && (ch != '"')) {
2183+
if ((codes[ch] != 0) && (ch != INT_QUOTE)) {
21842184
if (ch != '\\') {
21852185
// Unquoted white space?
21862186
// As per [JACKSON-208], call can now return:
@@ -2770,18 +2770,19 @@ protected JsonToken _handleApos() throws IOException
27702770
}
27712771
while (_inputPtr < max) {
27722772
c = (int) inputBuffer[_inputPtr++] & 0xFF;
2773-
if (c == INT_APOS || codes[c] != 0) {
2773+
if (c == INT_APOS) {
2774+
break main_loop;
2775+
}
2776+
if ((codes[c] != 0)
2777+
// 13-Oct-2021, tatu: [core#721] Alas, regular quote is included as
2778+
// special, need to ignore here
2779+
&& (c != INT_QUOTE)) {
27742780
break ascii_loop;
27752781
}
27762782
outBuf[outPtr++] = (char) c;
27772783
}
27782784
}
27792785

2780-
// Ok: end marker, escape or multi-byte?
2781-
if (c == INT_APOS) {
2782-
break main_loop;
2783-
}
2784-
27852786
switch (codes[c]) {
27862787
case 1: // backslash
27872788
c = _decodeEscaped();

src/test/java/com/fasterxml/jackson/core/read/NonStandardAposQuotedNamesTest.java

+58
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,62 @@ private void _testSingleQuotesEscaped(int mode) throws Exception
167167
assertToken(JsonToken.END_ARRAY, p.nextToken());
168168
p.close();
169169
}
170+
171+
// [core#721]: specific issue with enclosed unescaped double quotes
172+
public void testSingleQuotedKeys721() throws Exception
173+
{
174+
// empty
175+
_testSingleQuotedKeys721("{ '\"\"': 'value'}", "\"\"");
176+
// non-empty
177+
_testSingleQuotedKeys721("{ '\"key\"': 'value'}", "\"key\"");
178+
}
179+
180+
private void _testSingleQuotedKeys721(String doc, String expKey) throws Exception
181+
{
182+
_testSingleQuotedKeys721(MODE_READER, doc, expKey);
183+
_testSingleQuotedKeys721(MODE_INPUT_STREAM, doc, expKey);
184+
_testSingleQuotedKeys721(MODE_INPUT_STREAM_THROTTLED, doc, expKey);
185+
_testSingleQuotedKeys721(MODE_DATA_INPUT, doc, expKey);
186+
}
187+
188+
private void _testSingleQuotedKeys721(int mode, String doc, String expKey) throws Exception
189+
{
190+
JsonParser p = createParser(APOS_F, mode, doc);
191+
192+
assertToken(JsonToken.START_OBJECT, p.nextToken());
193+
assertEquals(expKey, p.nextFieldName());
194+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
195+
assertEquals("value", p.getText());
196+
assertToken(JsonToken.END_OBJECT, p.nextToken());
197+
p.close();
198+
}
199+
200+
// [core#721]: specific issue with enclosed unescaped double quotes
201+
public void testSingleQuotedValues721() throws Exception
202+
{
203+
// empty
204+
_testSingleQuotedValues721("{ \"bar\": '\"\"'}", "\"\"");
205+
// non-empty
206+
_testSingleQuotedValues721("{ \"bar\": '\"stuff\"'}", "\"stuff\"");
207+
}
208+
209+
private void _testSingleQuotedValues721(String doc, String expValue) throws Exception
210+
{
211+
_testSingleQuotedValues721(MODE_READER, doc, expValue);
212+
_testSingleQuotedValues721(MODE_INPUT_STREAM, doc, expValue);
213+
_testSingleQuotedValues721(MODE_INPUT_STREAM_THROTTLED, doc, expValue);
214+
_testSingleQuotedValues721(MODE_DATA_INPUT, doc, expValue);
215+
}
216+
217+
private void _testSingleQuotedValues721(int mode, String doc, String expValue) throws Exception
218+
{
219+
JsonParser p = createParser(APOS_F, mode, doc);
220+
221+
assertToken(JsonToken.START_OBJECT, p.nextToken());
222+
assertEquals("bar", p.nextFieldName());
223+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
224+
assertEquals(expValue, p.getText());
225+
assertToken(JsonToken.END_OBJECT, p.nextToken());
226+
p.close();
227+
}
170228
}

0 commit comments

Comments
 (0)