SANDBOX-313: Endless loops in CSV parser when last line is comment
git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@964273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
02b21463e6
commit
4dfc8ed074
|
@ -343,7 +343,7 @@ public class CSVParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// important: make sure a new char gets consumed in each iteration
|
// important: make sure a new char gets consumed in each iteration
|
||||||
while (!tkn.isReady) {
|
while (!tkn.isReady && tkn.type != TT_EOF) {
|
||||||
// ignore whitespaces at beginning of a token
|
// ignore whitespaces at beginning of a token
|
||||||
while (strategy.getIgnoreLeadingWhitespaces() && isWhitespace(c) && !eol) {
|
while (strategy.getIgnoreLeadingWhitespaces() && isWhitespace(c) && !eol) {
|
||||||
wsBuf.append((char) c);
|
wsBuf.append((char) c);
|
||||||
|
|
|
@ -497,7 +497,7 @@ public class CSVParserTest extends TestCase {
|
||||||
String[][] res = {
|
String[][] res = {
|
||||||
{ "a", "b" },
|
{ "a", "b" },
|
||||||
{ "\n", " " },
|
{ "\n", " " },
|
||||||
{ "", "#" }, // WARNING: TODO: this causes a hang if comments are enabled
|
{ "", "#" },
|
||||||
};
|
};
|
||||||
|
|
||||||
CSVStrategy strategy = CSVStrategy.DEFAULT_STRATEGY;
|
CSVStrategy strategy = CSVStrategy.DEFAULT_STRATEGY;
|
||||||
|
@ -510,6 +510,20 @@ public class CSVParserTest extends TestCase {
|
||||||
if (!CSVPrinterTest.equals(res, tmp)) {
|
if (!CSVPrinterTest.equals(res, tmp)) {
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[][] res_comments = {
|
||||||
|
{ "a", "b" },
|
||||||
|
{ "\n", " " },
|
||||||
|
{ ""},
|
||||||
|
};
|
||||||
|
|
||||||
|
strategy = new CSVStrategy(',','"','#');
|
||||||
|
parser = new CSVParser(new StringReader(code), strategy);
|
||||||
|
tmp = parser.getAllValues();
|
||||||
|
|
||||||
|
if (!CSVPrinterTest.equals(res_comments, tmp)) {
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -133,9 +133,15 @@ public class CSVPrinterTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equals(String[][] a, String[][] b) {
|
public static boolean equals(String[][] a, String[][] b) {
|
||||||
|
if (a.length != b.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (int i=0; i<a.length; i++) {
|
for (int i=0; i<a.length; i++) {
|
||||||
String[] linea = a[i];
|
String[] linea = a[i];
|
||||||
String[] lineb = b[i];
|
String[] lineb = b[i];
|
||||||
|
if (linea.length != lineb.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (int j=0; j<linea.length; j++) {
|
for (int j=0; j<linea.length; j++) {
|
||||||
String aval = linea[j];
|
String aval = linea[j];
|
||||||
String bval = lineb[j];
|
String bval = lineb[j];
|
||||||
|
|
Loading…
Reference in New Issue