Skip to content

Commit ce34196

Browse files
committed
Fixing bug reported byu Markus Rogg in #SANDBOX-153. Whitespace was being treated specially when it was not the delimiter. Unit test and patch applied.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/csv/trunk@427470 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5c76eab commit ce34196

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/java/org/apache/commons/csv/CSVParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public CSVStrategy getStrategy() {
557557
* @return true if the given char is a whitespace character
558558
*/
559559
private boolean isWhitespace(int c) {
560-
return Character.isWhitespace((char) c);
560+
return Character.isWhitespace((char) c) && (c != strategy.getDelimiter());
561561
}
562562

563563
/**

src/test/org/apache/commons/csv/CSVParserTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,18 @@ public void testLineTokenConsistency() throws IOException {
526526
}
527527
}
528528
}
529+
530+
// From SANDBOX-153
531+
public void testDelimiterIsWhitespace() throws IOException {
532+
String code = "one\ttwo\t\tfour \t five\t six";
533+
TestCSVParser parser = new TestCSVParser(new StringReader(code));
534+
parser.setStrategy(CSVStrategy.TDF_STRATEGY);
535+
System.out.println("---------\n" + code + "\n-------------");
536+
assertEquals(CSVParser.TT_TOKEN + ";one;", parser.testNextToken());
537+
assertEquals(CSVParser.TT_TOKEN + ";two;", parser.testNextToken());
538+
assertEquals(CSVParser.TT_TOKEN + ";;", parser.testNextToken());
539+
assertEquals(CSVParser.TT_TOKEN + ";four;", parser.testNextToken());
540+
assertEquals(CSVParser.TT_TOKEN + ";five;", parser.testNextToken());
541+
assertEquals(CSVParser.TT_EOF + ";six;", parser.testNextToken());
542+
}
529543
}

0 commit comments

Comments
 (0)