Skip to content

Commit 6b422c8

Browse files
committed
Fix for issue reported in SANDBOX-218: CSV reader doesn't handle older Mac line endings (\r) that are also used by recent versions of Excel for Mac.
git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@1065496 13f79535-47bb-0310-9956-ffa450edef68
1 parent cfcca02 commit 6b422c8

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ protected Token nextToken(Token tkn) throws IOException {
322322
// empty line detection: eol AND (last char was EOL or beginning)
323323
while (strategy.getIgnoreEmptyLines() && eol
324324
&& (lastChar == '\n'
325+
|| lastChar == '\r'
325326
|| lastChar == ExtendedBufferedReader.UNDEFINED)
326327
&& !isEndOfFile(lastChar)) {
327328
// go on char ahead ...
@@ -580,7 +581,7 @@ private boolean isWhitespace(int c) {
580581
}
581582

582583
/**
583-
* Greedy - accepts \n and \r\n
584+
* Greedy - accepts \n, \r and \r\n
584585
* This checker consumes silently the second control-character...
585586
*
586587
* @return true if the given character is a line-terminator
@@ -593,7 +594,7 @@ private boolean isEndOfLine(int c) throws IOException {
593594
c = in.read();
594595
}
595596
}
596-
return (c == '\n');
597+
return (c == '\n' || c == '\r');
597598
}
598599

599600
/**

0 commit comments

Comments
 (0)