diff --git a/src/main/java/com/univocity/parsers/csv/CsvFormatDetector.java b/src/main/java/com/univocity/parsers/csv/CsvFormatDetector.java index 8b8e53ac..e663e7c6 100644 --- a/src/main/java/com/univocity/parsers/csv/CsvFormatDetector.java +++ b/src/main/java/com/univocity/parsers/csv/CsvFormatDetector.java @@ -116,7 +116,14 @@ public void execute(char[] characters, int length) { inQuote = '\0'; } else if (inQuote == '\0') { - inQuote = ch; + char prev = '\0'; + int j = i; + while (prev <= ' ' && --j >= 0) { + prev = characters[j]; + } + if (j < 0 || !Character.isLetterOrDigit(prev)) { + inQuote = ch; + } } continue; } diff --git a/src/test/java/com/univocity/parsers/issues/github/Github_178.java b/src/test/java/com/univocity/parsers/issues/github/Github_178.java index 07173d8d..ffabd1a8 100644 --- a/src/test/java/com/univocity/parsers/issues/github/Github_178.java +++ b/src/test/java/com/univocity/parsers/issues/github/Github_178.java @@ -16,10 +16,12 @@ package com.univocity.parsers.issues.github; import com.univocity.parsers.*; +import com.univocity.parsers.common.processor.*; import com.univocity.parsers.csv.*; import org.testng.annotations.*; import java.io.*; +import java.util.*; import static org.testng.Assert.*; @@ -51,4 +53,32 @@ public void testDetectionOnInputWithoutExplicitCharset(char delimiter, String in assertEquals(parser.getDetectedFormat().getDelimiter(), delimiter); } + + @Test + public void testAnotherInput() { + String input = "" + + "Matricule;Nom;Prenoms;Classe;Date de naissance;Date d'inscription;Tel\n" + + " 'A12075';Mako;yao;6eme1;'01/02/2007';15/10/2015;'07108954'\n" + + "A12076; 'Mako';yao;6eme1;01/02/2007;15/10/2015;07108954\n" + + "'A12087';Mako;yao;6eme1;01/02/2007;15/10/2015;07108954"; + + + CsvParserSettings parserSettings = new CsvParserSettings(); + parserSettings.setLineSeparatorDetectionEnabled(true); + parserSettings.setDelimiterDetectionEnabled(true); + parserSettings.setQuoteDetectionEnabled(true); + + RowListProcessor rowProcessor = new RowListProcessor(); + parserSettings.setProcessor(rowProcessor); + parserSettings.setHeaderExtractionEnabled(true); + CsvParser parser = new CsvParser(parserSettings); + + parser.parseAll(new StringReader(input)); + List lignerslt = rowProcessor.getRows(); + + assertEquals(lignerslt.size(), 3); + assertEquals(Arrays.toString(lignerslt.get(0)), "[A12075, Mako, yao, 6eme1, 01/02/2007, 15/10/2015, 07108954]"); + assertEquals(Arrays.toString(lignerslt.get(1)), "[A12076, Mako, yao, 6eme1, 01/02/2007, 15/10/2015, 07108954]"); + assertEquals(Arrays.toString(lignerslt.get(2)), "[A12087, Mako, yao, 6eme1, 01/02/2007, 15/10/2015, 07108954]"); + } }