Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"keboola/coding-standard": "^13.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": ">=7.5"
"phpunit/phpunit": ">=7.5",
"phpstan/phpdoc-parser": "1.5.*"
},
"scripts": {
"phpstan": "phpstan analyse ./src ./tests --level=max --no-progress -c phpstan.neon",
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ parameters:
count: 1
path: src/CsvReader.php

-
message: "#^PHPDoc tag @param has invalid value \\(\\$fileName\\)\\: Unexpected token \"\\$fileName\", expected type at offset 18$#"
count: 1
path: src/CsvReader.php

-
message: "#^Parameter \\#1 \\$header of static method Keboola\\\\Csv\\\\UTF8BOMHelper\\:\\:detectAndRemoveBOM\\(\\) expects array, array\\|false\\|null given\\.$#"
count: 1
Expand Down
4 changes: 4 additions & 0 deletions src/LineBreaksHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static function detectLineBreaks($sample, $enclosure, $escapedBy)
*/
public static function clearCsvValues($sample, $enclosure, $escapedBy)
{
if (empty($enclosure)) {
return $sample;
}

// Usually an enclosure character is escaped by doubling it, however, the escapeBy can be used
$doubleEnclosure = $enclosure . $enclosure;
$escapedEnclosure = empty($escapedBy) ? $doubleEnclosure : $escapedBy . $enclosure;
Expand Down
22 changes: 22 additions & 0 deletions tests/LineBreaksHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public function getDataSet()
"\n",
];

yield 'empty-enclosure' => [
'',
'',
'col1|col2',
'col1|col2',
"\n",
];

yield 'empty-escaped-by' => [
'"',
'\\',
Expand All @@ -59,6 +67,20 @@ public function getDataSet()
];

foreach ($lineEnds as $prefix => $lineEnd) {
yield "$prefix-empty-enclosure" => [
'',
'',
implode($lineEnd, [
'col1,col2',
'abc,def',
]),
implode($lineEnd, [
'col1,col2',
'abc,def',
]),
$lineEnd,
];

yield "$prefix-simple" => [
'"',
'',
Expand Down