Skip to content

Commit 4496d13

Browse files
committed
Add YAML test, too, for #497
1 parent 5b2415e commit 4496d13

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fasterxml.jackson.dataformat.yaml.failing;
2+
3+
import java.nio.charset.StandardCharsets;
4+
5+
import com.fasterxml.jackson.core.JsonParser;
6+
import com.fasterxml.jackson.core.JsonToken;
7+
8+
import com.fasterxml.jackson.dataformat.yaml.*;
9+
10+
// [dataformats-text#497]: 3-byte UTF-8 character at end of content
11+
public class UnicodeYAMLRead497Test extends ModuleTestBase
12+
{
13+
private final YAMLMapper MAPPER = newObjectMapper();
14+
15+
// [dataformats-text#497]
16+
public void testUnicodeAtEnd() throws Exception
17+
{
18+
// Had to find edge condition, these would do:
19+
_testUnicodeAtEnd(1024);
20+
_testUnicodeAtEnd(2048);
21+
_testUnicodeAtEnd(3072);
22+
_testUnicodeAtEnd(4096);
23+
}
24+
25+
void _testUnicodeAtEnd(int LEN) throws Exception
26+
{
27+
StringBuilder sb = new StringBuilder(LEN + 2);
28+
sb.append("key: ");
29+
StringBuilder valueBuffer = new StringBuilder();
30+
31+
while ((sb.length() + valueBuffer.length()) < LEN) {
32+
valueBuffer.append('a');
33+
}
34+
valueBuffer.append('\u5496');
35+
36+
sb.append(valueBuffer);
37+
final byte[] doc = sb.toString().getBytes(StandardCharsets.UTF_8);
38+
39+
try (JsonParser p = MAPPER.createParser(doc)) {
40+
assertToken(JsonToken.START_OBJECT, p.nextToken());
41+
assertEquals("key", p.nextFieldName());
42+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
43+
assertEquals(valueBuffer.toString(), p.getText());
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)