Skip to content

Commit 69c844c

Browse files
committed
Minor fix to encoding of long UTF-8 text values
1 parent f90ccdf commit 69c844c

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,12 +1928,12 @@ private final void _finishString2(char[] outBuf, int outPtr, int c)
19281928
case 4: // 4-byte UTF
19291929
c = _decodeUtf8_4(c);
19301930
// Let's add first part right away:
1931-
outBuf[outPtr++] = (char) (0xD800 | (c >> 10));
19321931
if (outPtr >= outBuf.length) {
19331932
outBuf = _textBuffer.finishCurrentSegment();
19341933
outPtr = 0;
19351934
outEnd = outBuf.length;
19361935
}
1936+
outBuf[outPtr++] = (char) (0xD800 | (c >> 10));
19371937
c = 0xDC00 | (c & 0x3FF);
19381938
// And let the other char output down below
19391939
break;

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,20 @@ public void _testUtf8StringTrivial(int mode) throws Exception
157157

158158
public void testUtf8StringValue() throws Exception
159159
{
160-
_testUtf8StringValue(MODE_INPUT_STREAM);
161-
_testUtf8StringValue(MODE_DATA_INPUT);
162-
_testUtf8StringValue(MODE_INPUT_STREAM_THROTTLED);
160+
_testUtf8StringValue(MODE_INPUT_STREAM, 2900);
161+
_testUtf8StringValue(MODE_DATA_INPUT, 2900);
162+
_testUtf8StringValue(MODE_INPUT_STREAM_THROTTLED, 2900);
163+
164+
_testUtf8StringValue(MODE_INPUT_STREAM, 5300);
165+
_testUtf8StringValue(MODE_DATA_INPUT, 5300);
166+
_testUtf8StringValue(MODE_INPUT_STREAM_THROTTLED, 5300);
163167
}
164168

165-
public void _testUtf8StringValue(int mode) throws Exception
169+
public void _testUtf8StringValue(int mode, int len) throws Exception
166170
{
167171
Random r = new Random(13);
168-
//int LEN = 72000;
169-
int LEN = 720;
170-
StringBuilder sb = new StringBuilder(LEN + 20);
171-
while (sb.length() < LEN) {
172+
StringBuilder sb = new StringBuilder(len + 20);
173+
while (sb.length() < len) {
172174
int c;
173175
if (r.nextBoolean()) { // ascii
174176
c = 32 + (r.nextInt() & 0x3F);
@@ -188,7 +190,7 @@ public void _testUtf8StringValue(int mode) throws Exception
188190
sb.append((char) c);
189191
}
190192

191-
ByteArrayOutputStream bout = new ByteArrayOutputStream(LEN);
193+
ByteArrayOutputStream bout = new ByteArrayOutputStream(len + (len >> 2));
192194
OutputStreamWriter out = new OutputStreamWriter(bout, "UTF-8");
193195
out.write("[\"");
194196
String VALUE = sb.toString();

0 commit comments

Comments
 (0)