diff --git a/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/BasicParserTest.java b/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/BasicParserTest.java index b33751a..029d949 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/BasicParserTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/BasicParserTest.java @@ -173,7 +173,7 @@ private void _testMapsWithLinefeeds(boolean useBytes) throws Exception { mi.close(); } - // [Issue#12] + // [dataformat-csv#12] public void testEmptyHandlingForInteger() throws Exception { CsvSchema schema = MAPPER.typedSchemaFor(Point.class).withoutHeader(); @@ -194,7 +194,7 @@ public void testStringNullHandlingForInteger() throws Exception { assertNull(result.z); } - // [Issue#41] + // [dataformat-csv#41] public void testIncorrectDups41() throws Exception { final String INPUT = "\"foo\",\"bar\",\"foo\""; CsvSchema schema = CsvSchema.builder().addColumn("Col1").addColumn("Col2") @@ -215,7 +215,7 @@ public void testIncorrectDups41() throws Exception { assertEquals("foo", m.get("Col3")); } - // for pull request 89 + // for [dataformat-csv#89] public void testColumnReordering() throws IOException { CsvFactory factory = new CsvFactory(); String CSV = "b,a,c\nvb,va,vc\n"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserStrictQuoting.java b/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserStrictQuoting.java index 44c05b6..ad11447 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserStrictQuoting.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserStrictQuoting.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.dataformat.csv.*; -// Tests for [Issue#26] +// Tests for [dataformat-csv#26] public class TestParserStrictQuoting extends ModuleTestBase { @JsonPropertyOrder({"a", "b"}) @@ -16,7 +16,7 @@ public AB(String a, String b) { this.b = b; } } - + /* /********************************************************************** /* Test methods diff --git a/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/BrokenEncodingTest.java b/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/BrokenEncodingTest.java new file mode 100644 index 0000000..2168f5a --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/csv/failing/BrokenEncodingTest.java @@ -0,0 +1,51 @@ +package com.fasterxml.jackson.dataformat.csv.failing; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.dataformat.csv.*; + +public class BrokenEncodingTest extends ModuleTestBase +{ + /* + /********************************************************************** + /* Test methods + /********************************************************************** + */ + + public void testLatin1asUTF8() throws Exception + { + CsvFactory factory = new CsvFactory(); + String CSV = "1,2\nabc,\u00A0\n"; + + CsvSchema schema = CsvSchema.builder() + .addColumn("a") + .addColumn("b") + .build(); + // So: take Latin-1 bytes, but construct without specifying to lead to UTF-8 handling + CsvParser parser = factory.createParser(CSV.getBytes("ISO-8859-1")); + parser.setSchema(schema); + + assertToken(JsonToken.START_OBJECT, parser.nextToken()); + assertToken(JsonToken.FIELD_NAME, parser.nextToken()); + assertEquals("a", parser.getCurrentName()); + assertToken(JsonToken.VALUE_STRING, parser.nextToken()); + assertToken(JsonToken.FIELD_NAME, parser.nextToken()); + assertToken(JsonToken.VALUE_STRING, parser.nextToken()); + assertEquals("2", parser.getText()); + assertToken(JsonToken.END_OBJECT, parser.nextToken()); + + // problem should only be triggered now + assertToken(JsonToken.START_OBJECT, parser.nextToken()); + assertToken(JsonToken.FIELD_NAME, parser.nextToken()); + assertEquals("a", parser.getCurrentName()); + assertToken(JsonToken.VALUE_STRING, parser.nextToken()); + assertEquals("abc", parser.getText()); + try { + parser.nextToken(); + fail("Should trigger exception for invalid UTF-8 char"); + } catch (JsonParseException e) { + verifyException(e, "foobar"); + } + parser.close(); + } +}