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

Commit aef3ae4

Browse files
committed
Fix #100
1 parent 93dfe48 commit aef3ae4

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ Rob Baily (rob-baily@github)
6161
* Contributed fix for #93: CSV mapper does not support Views or filtering correctly
6262
for serialization
6363
(2.6.5)
64+
65+
dharaburda@github)
66+
67+
* Contributed fix for #100: trim spaces: don't trim/strip separator character
68+
(2.6.5)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,17 +908,18 @@ protected final int _nextChar() throws IOException
908908
}
909909
return _inputBuffer[_inputPtr++];
910910
}
911-
911+
912912
protected final int _skipLeadingSpace() throws IOException
913913
{
914+
final int sep = _separatorChar;
914915
while (true) {
915916
if (_inputPtr >= _inputEnd) {
916917
if (!loadMore()) {
917918
return -1;
918919
}
919920
}
920921
char ch = _inputBuffer[_inputPtr++];
921-
if (ch > ' ') {
922+
if ((ch > ' ') || (ch == sep)) {
922923
return ch;
923924
}
924925
switch (ch) {
@@ -928,7 +929,7 @@ protected final int _skipLeadingSpace() throws IOException
928929
}
929930
}
930931
}
931-
932+
932933
/*
933934
/**********************************************************************
934935
/* Numeric accessors for CsvParser

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,38 @@ public void testTrimming() throws Exception
8080
assertFalse(it.hasNext());
8181
it.close();
8282
}
83+
84+
// for [dataformat-csv#100]: Do not eat tabs when trimming space
85+
public void testTrimmingTabSeparated() throws Exception
86+
{
87+
CsvMapper mapper = mapperForCsv();
88+
mapper.enable(CsvParser.Feature.TRIM_SPACES);
89+
CsvSchema schema = mapper.schemaFor(Entry.class).withColumnSeparator('\t');
90+
MappingIterator<Entry> it = mapper.readerFor(Entry.class).with(schema).
91+
readValues(
92+
"a\t\t c\n 1\t2\t\" 3\" \n\"ab\" \t\"c \t\"\t \n"
93+
);
94+
Entry entry;
95+
96+
assertTrue(it.hasNext());
97+
assertNotNull(entry = it.nextValue());
98+
assertEquals("a", entry.a);
99+
assertEquals("", entry.b);
100+
assertEquals("c", entry.c);
101+
102+
assertTrue(it.hasNext());
103+
assertNotNull(entry = it.nextValue());
104+
assertEquals("1", entry.a);
105+
assertEquals("2", entry.b);
106+
assertEquals(" 3", entry.c); // note: space within quotes is preserved
107+
108+
assertTrue(it.hasNext());
109+
assertNotNull(entry = it.nextValue());
110+
assertEquals("ab", entry.a);
111+
assertEquals("c \t", entry.b);
112+
assertEquals("", entry.c);
113+
114+
assertFalse(it.hasNext());
115+
it.close();
116+
}
83117
}

0 commit comments

Comments
 (0)