Skip to content

Commit

Permalink
Issue #133 - "ignoreSurroundingSpaces" doesn't ignore trailing spaces (
Browse files Browse the repository at this point in the history
  • Loading branch information
kosak authored Aug 9, 2023
1 parent 73f229e commit ced4780
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/deephaven/csv/reading/CellGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public boolean grabNext(final ByteSlice dest, final MutableBoolean lastInRow)
}
} else {
processUnquotedMode(dest, lastInRow);
if (ignoreSurroundingSpaces) {
trimWhitespace(dest);
}
}
return true;
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/io/deephaven/csv/CsvReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ public void bug101() throws CsvReaderException {
CsvReader.read(specs, inputStream, makeMySinkFactory());
}

/**
* Addresses <a href="https://github.com/deephaven/deephaven-csv/issues/133">Deephaven CSV Issue #133</a>.
* The library was not trimming trailing whitespace in unquoted strings when requested.
*/
@Test
public void bug133() throws CsvReaderException {
final String input = "String1,String2\n" +
"hello , there\n";

final ColumnSet includingSpaces =
ColumnSet.of(
Column.ofRefs("String1", "hello "), // including surrounding spaces
Column.ofRefs("String2", " there"));

final ColumnSet ignoringSpaces =
ColumnSet.of(
Column.ofRefs("String1", "hello"), // ignoring surrounding spaces
Column.ofRefs("String2", "there"));

invokeTest(defaultCsvBuilder().parsers(Parsers.DEFAULT).ignoreSurroundingSpaces(false).build(), input, includingSpaces);
invokeTest(defaultCsvBuilder().parsers(Parsers.DEFAULT).ignoreSurroundingSpaces(true).build(), input, ignoringSpaces);
}

@Test
public void validates() {
final String lengthyMessage = "CsvSpecs failed validation for the following reasons: "
Expand Down

0 comments on commit ced4780

Please sign in to comment.