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

Commit dc223c2

Browse files
author
David Navas
committed
Support escapes at beginning of the file
1 parent d983359 commit dc223c2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,17 @@ public String nextString() throws IOException
563563
_textBuffer.resetWithString("");
564564
return "";
565565
}
566+
566567
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
567568
outBuf[0] = (char) i;
568569
int outPtr = 1;
569570

571+
if (i == _escapeChar) {
572+
// Reset the escaped character
573+
outBuf[0] = _unescape();
574+
return _nextUnquotedString(outBuf, outPtr);
575+
}
576+
570577
int ptr = _inputPtr;
571578
if (ptr >= _inputEnd) {
572579
if (!loadMore()) { // ok to have end-of-input but...

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,16 @@ public void testSimpleEscapesInUnquoted() throws Exception
4747
assertEquals("abc\\def", result.id);
4848
assertEquals("Desc with\nlinefeed", result.desc);
4949
}
50-
50+
51+
public void testEscapesAtStartInUnquoted() throws Exception
52+
{
53+
CsvMapper mapper = mapperForCsv();
54+
CsvSchema schema = mapper.schemaFor(Desc.class).withColumnSeparator('|').withEscapeChar('\\');
55+
final String id = "\\|abcdef"; // doubled for javac
56+
final String desc = "Desc with\\\nlinefeed";
57+
String input = id+"|"+desc+"\n";
58+
Desc result = mapper.reader(schema).withType(Desc.class).readValue(input);
59+
assertEquals("|abcdef", result.id);
60+
assertEquals("Desc with\nlinefeed", result.desc);
61+
}
5162
}

0 commit comments

Comments
 (0)