diff --git a/.editorconfig b/.editorconfig index 8b42575..c49e144 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,8 @@ [*] charset=utf-8 end_of_line=lf + +[*.php] trim_trailing_whitespace=true insert_final_newline=true indent_style=space diff --git a/src/ParserCSV.php b/src/ParserCSV.php index 63b12c4..232b688 100644 --- a/src/ParserCSV.php +++ b/src/ParserCSV.php @@ -46,7 +46,7 @@ public static function csvToArray($csv, $delimiter = ',', $enclosure = '\'', $es $tabTemp = array(); // array_combine($names,$values); foreach ($names as $key => $nameCol) { - if (isset($values[$key])) { + if (isset($values[$key]) && ! empty($values[$key])) { $value = $values[$key]; if (strpos($value,'"')===0 || strpos($value,"'")===0){ $value = trim($value,'"'); diff --git a/tests/ParserCsvTest.php b/tests/ParserCsvTest.php index d4b567a..802ea9e 100644 --- a/tests/ParserCsvTest.php +++ b/tests/ParserCsvTest.php @@ -15,16 +15,7 @@ final class ParserCsvTest extends TestCase public function testParserTsv() { //check write - $sample = << "foo" - "foo" - "bar" - 4 - 5.5 - _:b0 - "10" -EOT; + $sample = file_get_contents (__DIR__ . "/csvtsv02.tsv"); $expected = [ 0 => [ "?s" => "", @@ -78,11 +69,11 @@ public function testParserTsv() ]; //"text/tab-separated-values; charset=utf-8": $tabResultDataset = ParserCSV::csvToArray($sample,"\t"); - $sort = false; + $sort = true; $distinct = false; $tabDiff = ParserCSV::compare($expected,$tabResultDataset,$sort,$distinct); -// print_r($tabDiff); -// print_r($tabResultDataset); + print_r($tabDiff); + print_r($tabResultDataset); $this->assertTrue(count($tabDiff)==0,print_r($tabDiff,true)); } diff --git a/tests/csvtsv02.tsv b/tests/csvtsv02.tsv new file mode 100644 index 0000000..08eb753 --- /dev/null +++ b/tests/csvtsv02.tsv @@ -0,0 +1,8 @@ +?s ?p ?o ?p2 ?o2 + "foo" + "foo" + "bar" + 4 + 5.5 + _:b0 + "10"