Skip to content

Commit 3fd45b5

Browse files
committed
Have to check for comment after dealing with empty lines.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306667 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9ce0716 commit 3fd45b5

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/main/java/org/apache/commons/csv/CSVLexer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ Token nextToken(Token tkn) throws IOException {
4646
// read the next char and set eol
4747
int c = in.read();
4848

49-
if (isStartOfLine(lastChar) && isCommentStart(c)) {
50-
in.readLine();
51-
tkn.type = COMMENT;
52-
return tkn;
53-
}
54-
5549
/* note: unfortunately isEndOfLine may consumes a character silently.
5650
* this has no effect outside of the method. so a simple workaround
5751
* is to call 'readAgain' on the stream...
@@ -83,6 +77,12 @@ Token nextToken(Token tkn) throws IOException {
8377
return tkn;
8478
}
8579

80+
if (isStartOfLine(lastChar) && isCommentStart(c)) {
81+
in.readLine();
82+
tkn.type = COMMENT;
83+
return tkn;
84+
}
85+
8686
// important: make sure a new char gets consumed in each iteration
8787
while (tkn.type == INVALID) {
8888
// ignore whitespaces at beginning of a token

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ public void testNextToken1() throws IOException {
5858
public void testNextToken2() throws IOException {
5959
final String code =
6060
"1,2,3,\n"+ // 1
61+
"\n"+
62+
"\n"+
6163
"a,b x,c#no-comment\n"+ // 2
64+
"\n"+
65+
"\n"+
6266
"#foo\n"+ // 3
6367
"\n"+ // 4
6468
"d,e,#no-comment\n"+ // 5
69+
"\n"+
70+
"\n"+
6571
"# penultimate comment\n"+ // 6
72+
"\n"+
73+
"\n"+
6674
"# Final comment\n"; // 7
6775
CSVFormat format = CSVFormat.DEFAULT.withCommentStart('#');
6876
assertTrue("Should ignore empty lines", format.isEmptyLinesIgnored());

0 commit comments

Comments
 (0)