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

Commit

Permalink
Backport #54 fix for 2.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 3, 2014
1 parent f639f66 commit 503aca7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
6 changes: 6 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ Jason Dunkelberger (dirkraft@github)

* Suggested #32: Allow disabling of quoteChar
(2.4.0)

Wei Li (wli600@github)

* Contributed fix for 54: Encounter ArrayIndexOutOfBoundsException in the corner case delimiter
or end-of-line happened to be the leading character of a segment buffer
(2.4.4)
6 changes: 6 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Project: jackson-dataformat-csv
#53: Add a way to specify "null value" (String) for `CsvGenerator` to use when writing `null`s
(part of `CsvSchema`; method `withNullValue()`)

2.4.4 (not yet released)

#54: Encounter ArrayIndexOutOfBoundsException in the corner case delimiter or end-of-line
happened to be the leading character of a segment buffer
(contributed by wli600@github)

2.4.3 (04-Oct-2014)

- Support JDK serializability of CsvMapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,17 @@ public int getCurrentSegmentSize() {
}

/**
*
* @param lastSegmentEnd End offset in the currently active segment
* @param lastSegmentEnd End offset in the currently active segment,
* could be 0 in the case of first character is
* delimiter or end-of-line
* @param trimTrailingSpaces Whether trailing spaces should be trimmed or not
*/
public String finishAndReturn(int lastSegmentEnd, boolean trimTrailingSpaces)
{
if (trimTrailingSpaces) {
// First, see if it's enough to trim end of current segment:
int ptr = lastSegmentEnd-1;
if (_currentSegment[ptr] <= 0x0020) {
int ptr = lastSegmentEnd - 1;
if (ptr < 0 || _currentSegment[ptr] <= 0x0020) {
return _doTrim(ptr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,37 @@ public void testUntypedAsSequenceVarLengths() throws Exception
it.close();
}

// [Issue#54]
public void testDelimiterAtBufferBoundary() throws Exception
{
CsvMapper mapper = mapperForCsv();
mapper.enable(CsvParser.Feature.TRIM_SPACES);

final String col1 = "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
final String col2 = "H";

CsvParser cp = mapper.getFactory().createParser(col1 + " ," + col2 +"\n" + col2 + "," + col1 + "\n");
MappingIterator<Object[]> it = mapper.reader(Object[].class).readValues(cp);

Object[] row;

assertTrue(it.hasNext());
row = it.next();
assertEquals(2, row.length);
assertEquals(col1, row[0]);
assertEquals(col2, row[1]);

assertTrue(it.hasNext());
row = it.next();
assertEquals(2, row.length);
assertEquals(col2, row[0]);
assertEquals(col1, row[1]);

cp.close();
it.close();
}

}

0 comments on commit 503aca7

Please sign in to comment.