Skip to content

Commit

Permalink
Add YAML test, too, for #497
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 24, 2024
1 parent 5b2415e commit 4496d13
Showing 1 changed file with 46 additions and 0 deletions.
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());
}
}
}

0 comments on commit 4496d13

Please sign in to comment.