Skip to content

Commit 0e6016d

Browse files
authored
add utf8 parsing test (#1404)
1 parent e0cd540 commit 0e6016d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.fasterxml.jackson.core.read;
2+
3+
import com.fasterxml.jackson.core.JUnit5TestBase;
4+
import com.fasterxml.jackson.core.JsonParser;
5+
import com.fasterxml.jackson.core.JsonToken;
6+
import com.fasterxml.jackson.core.TokenStreamFactory;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
class UTF8ParsingTest extends JUnit5TestBase
12+
{
13+
private TokenStreamFactory JSON_F = newStreamFactory();
14+
15+
final String testValue = createTestString();
16+
final String INPUT_JSON = a2q("{ 'value': '" + testValue + "' }");
17+
18+
// https://github.com/FasterXML/jackson-dataformats-text/issues/497
19+
@Test
20+
public void utf8Char3Bytes() throws Exception
21+
{
22+
for (int mode : ALL_MODES) {
23+
testIssue(JSON_F, mode, INPUT_JSON);
24+
}
25+
}
26+
27+
private void testIssue(final TokenStreamFactory jsonF,
28+
final int mode,
29+
final String json) throws Exception
30+
{
31+
try (JsonParser p = createParser(jsonF, mode, json)) {
32+
assertToken(JsonToken.START_OBJECT, p.nextToken());
33+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
34+
assertEquals("value", p.currentName());
35+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
36+
assertEquals(testValue, p.getText());
37+
assertToken(JsonToken.END_OBJECT, p.nextToken());
38+
}
39+
}
40+
41+
private static String createTestString() {
42+
StringBuilder sb = new StringBuilder(4001);
43+
for (int i = 0; i < 4000; ++i) {
44+
sb.append('a');
45+
}
46+
sb.append('\u5496');
47+
return sb.toString();
48+
}
49+
}

0 commit comments

Comments
 (0)