diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 7b1ff8a..4c5b7cc 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -905,8 +905,8 @@ class parseCSV { /** * Validate a row against a single condition * - * @param array $row array with values from a row - * @param string $condition specified condition that the row must match + * @param array $row array with values from a row + * @param string $condition specified condition that the row must match * * @return string single 0 or 1 */ @@ -1181,7 +1181,12 @@ class parseCSV { $enclosed = false; $current_row = 1; $to_end = true; - $pattern = '/[' . preg_quote($this->auto_non_chars, '/') . ']/i'; + + // The dash is the only character we don't want quoted, as it would + // prevent character ranges within $auto_non_chars: + $quoted_auto_non_chars = preg_quote($this->auto_non_chars, '/'); + $quoted_auto_non_chars = str_replace('\-', '-', $quoted_auto_non_chars); + $pattern = '/[' . $quoted_auto_non_chars . ']/i'; // walk specific depth finding possible delimiter characters for ($i = 0; $i < $strlen; $i++) { diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 37fe8f0..f05781a 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -52,6 +52,16 @@ class ParseTest extends PHPUnit\Framework\TestCase { $this->assertEquals($expected_data, $row); } + public function testAllNumericalCsv() { + $this->csv->heading = false; + $sInput = "86545235689\r\n34365587654\r\n13469874576"; + $this->assertEquals(false, $this->csv->auto($sInput)); + $this->assertEquals(null, $this->csv->delimiter); + $expected_data = explode("\r\n", $sInput); + $actual_data = array_map('reset', $this->csv->data); + $this->assertEquals($expected_data, $actual_data); + } + public function test_sep_row_auto_detection_UTF8() { $this->_autoparse_magazine_file( __DIR__ . '/../example_files/UTF-8_with_BOM_and_sep_row.csv');