This repository has been archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
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
87bb0d1
commit a3045b7
Showing
3 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
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
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
51 changes: 51 additions & 0 deletions
51
src/test/java/com/fasterxml/jackson/dataformat/csv/failing/BrokenEncodingTest.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,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(); | ||
} | ||
} |