diff --git a/src/main/java/io/deephaven/csv/reading/CellGrabber.java b/src/main/java/io/deephaven/csv/reading/CellGrabber.java index 73ddf59e..3c7da931 100644 --- a/src/main/java/io/deephaven/csv/reading/CellGrabber.java +++ b/src/main/java/io/deephaven/csv/reading/CellGrabber.java @@ -101,6 +101,9 @@ public boolean grabNext(final ByteSlice dest, final MutableBoolean lastInRow) } } else { processUnquotedMode(dest, lastInRow); + if (ignoreSurroundingSpaces) { + trimWhitespace(dest); + } } return true; } diff --git a/src/test/java/io/deephaven/csv/CsvReaderTest.java b/src/test/java/io/deephaven/csv/CsvReaderTest.java index 7c3f49ae..45a894bd 100644 --- a/src/test/java/io/deephaven/csv/CsvReaderTest.java +++ b/src/test/java/io/deephaven/csv/CsvReaderTest.java @@ -159,6 +159,29 @@ public void bug101() throws CsvReaderException { CsvReader.read(specs, inputStream, makeMySinkFactory()); } + /** + * Addresses Deephaven CSV Issue #133. + * 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: "