-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b2415e
commit 4496d13
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/UnicodeYAMLRead497Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.fasterxml.jackson.dataformat.yaml.failing; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
|
||
import com.fasterxml.jackson.dataformat.yaml.*; | ||
|
||
// [dataformats-text#497]: 3-byte UTF-8 character at end of content | ||
public class UnicodeYAMLRead497Test extends ModuleTestBase | ||
{ | ||
private final YAMLMapper MAPPER = newObjectMapper(); | ||
|
||
// [dataformats-text#497] | ||
public void testUnicodeAtEnd() throws Exception | ||
{ | ||
// Had to find edge condition, these would do: | ||
_testUnicodeAtEnd(1024); | ||
_testUnicodeAtEnd(2048); | ||
_testUnicodeAtEnd(3072); | ||
_testUnicodeAtEnd(4096); | ||
} | ||
|
||
void _testUnicodeAtEnd(int LEN) throws Exception | ||
{ | ||
StringBuilder sb = new StringBuilder(LEN + 2); | ||
sb.append("key: "); | ||
StringBuilder valueBuffer = new StringBuilder(); | ||
|
||
while ((sb.length() + valueBuffer.length()) < LEN) { | ||
valueBuffer.append('a'); | ||
} | ||
valueBuffer.append('\u5496'); | ||
|
||
sb.append(valueBuffer); | ||
final byte[] doc = sb.toString().getBytes(StandardCharsets.UTF_8); | ||
|
||
try (JsonParser p = MAPPER.createParser(doc)) { | ||
assertToken(JsonToken.START_OBJECT, p.nextToken()); | ||
assertEquals("key", p.nextFieldName()); | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
assertEquals(valueBuffer.toString(), p.getText()); | ||
} | ||
} | ||
} |