Skip to content

add test for utf8 issue (497) #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.StringReader;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.time.*;
import java.util.Arrays;

Expand Down Expand Up @@ -32,6 +33,10 @@ static ObjectNode toml(@Language("toml") String toml) throws Exception {
return (ObjectNode) TOML_MAPPER.readTree(toml);
}

static ObjectNode tomlBytes(@Language("toml") String toml) throws Exception {
return (ObjectNode) TOML_MAPPER.readTree(toml.getBytes(StandardCharsets.UTF_8));
}

static ObjectNode toml(TomlFactory factory, @Language("toml") String toml) throws Exception {
return Parser.parse(
factory, testIOContext(),
Expand Down Expand Up @@ -1057,9 +1062,33 @@ public void chunkEdge() throws Exception {
assertEquals(123, node.get("bar").intValue());
}

// https://github.com/FasterXML/jackson-dataformats-text/issues/497
@Test
public void issue497() throws Exception {
final String testValue = createIssue497String();
final String tomlText = "test = \"" + testValue + "\"";

ObjectNode node = toml(tomlText);
assertEquals(testValue, node.get("test").asText());

// test again with byte[]
node = tomlBytes(tomlText);
assertEquals(testValue, node.get("test").asText());

}

private static String repeat(char c, int n) {
char[] chars = new char[n];
Arrays.fill(chars, c);
return new String(chars);
}

private static String createIssue497String() {
StringBuilder sb = new StringBuilder(4001);
for (int i = 0; i < 4000; ++i) {
sb.append('a');
}
sb.append('\u5496');
return sb.toString();
}
}