Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 3492030

Browse files
committed
Backport #75 in 2.5(.3)
1 parent 5e5ecfa commit 3492030

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

release-notes/CREDITS

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ Luke Nezda (nezda@github)
3434
* Suggested #56: Support comments (either via `CsvSchema`, or using std
3535
`JsonParser.Feature.ALLOW_YAML_COMMENTS.
3636
(requested by nezda@github)
37-
(2.5.0)
37+
(2.5.0)
38+
39+
David Navas (davidnavas@github)
40+
41+
* Contributed #75: Support escapes at beginning of the file
42+
(2.5.3)
43+
44+

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-dataformat-csv
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.5.3 (not yet released)
8+
9+
#75: Support escapes at beginning of the file
10+
(contributed by David N)
11+
712
2.5.2 (29-Mar-2015)
813

914
#66: Deserializing an empty string as an array field return a non-empty list of one empty String

src/main/java/com/fasterxml/jackson/dataformat/csv/impl/CsvDecoder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ public String nextString() throws IOException
632632
outBuf[0] = (char) i;
633633
int outPtr = 1;
634634

635+
if (i == _escapeChar) {
636+
// Reset the escaped character
637+
outBuf[0] = _unescape();
638+
return _nextUnquotedString(outBuf, outPtr);
639+
}
640+
635641
int ptr = _inputPtr;
636642
if (ptr >= _inputEnd) {
637643
if (!loadMore()) { // ok to have end-of-input but...

src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserEscapes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,15 @@ public void testSimpleEscapesInUnquoted() throws Exception
5151
assertEquals("Desc with\nlinefeed", result.desc);
5252
}
5353

54+
public void testEscapesAtStartInUnquoted() throws Exception
55+
{
56+
CsvMapper mapper = mapperForCsv();
57+
CsvSchema schema = mapper.schemaFor(Desc.class).withColumnSeparator('|').withEscapeChar('\\');
58+
final String id = "\\|abcdef"; // doubled for javac
59+
final String desc = "Desc with\\\nlinefeed";
60+
String input = id+"|"+desc+"\n";
61+
Desc result = mapper.reader(schema).withType(Desc.class).readValue(input);
62+
assertEquals("|abcdef", result.id);
63+
assertEquals("Desc with\nlinefeed", result.desc);
64+
}
5465
}

0 commit comments

Comments
 (0)