Fix bug when both trim and autodetect are enabled in tabular parser. Closes #2584 (#2610)

This commit is contained in:
Antonin Delpeuch 2020-05-05 14:00:17 +02:00 committed by GitHub
parent 15710ace17
commit 825e687b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -167,11 +167,12 @@ abstract public class TabularImportingParserBase extends ImportingParserBase {
} else if (ExpressionUtils.isNonBlankData(value)) {
Serializable storedValue;
if (value instanceof String) {
if(trimStrings) {
value = ((String) value).trim();
}
storedValue = guessCellValueTypes ?
ImporterUtilities.parseCellValue((String) value) : (String) value;
if(trimStrings) {
storedValue = ((String) storedValue).toString().trim();
}
} else {
storedValue = ExpressionUtils.wrapStorable(value);
}

View File

@ -245,6 +245,27 @@ public class TsvCsvImporterTests extends ImporterTest {
Assert.assertEquals(project.rows.get(0).cells.get(1).value, " 3.4 ");
Assert.assertEquals(project.rows.get(0).cells.get(2).value, " data3 ");
}
@Test(groups = { }, dataProvider = "CSV-TSV-AutoDetermine")
public void trimAndAutodetectDatatype(String sep){
//create input to test with
String inputSeparator = sep == null ? "\t" : sep;
String input = " data1 " + inputSeparator + " 3.4 " + inputSeparator + " data3 ";
try {
prepareOptions(sep, -1, 0, 0, 0, true, false, true);
parseOneFile(SUT, new StringReader(input));
} catch (Exception e) {
Assert.fail("Exception during file parse",e);
}
Assert.assertEquals(project.columnModel.columns.size(), 3);
Assert.assertEquals(project.rows.size(), 1);
Assert.assertEquals(project.rows.get(0).cells.size(), 3);
Assert.assertEquals(project.rows.get(0).cells.get(0).value, "data1");
Assert.assertEquals(project.rows.get(0).cells.get(1).value, Double.parseDouble("3.4"));
Assert.assertEquals(project.rows.get(0).cells.get(2).value, "data3");
}
@Test(dataProvider = "CSV-TSV-AutoDetermine")
public void readCanAddNull(String sep){