Skip to content

Commit 82cc689

Browse files
authored
Merge pull request #47 from keboola/ondra-fix-empty-enclosure
Fix empty enclosure
2 parents 65000f3 + 2f669dc commit 82cc689

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"keboola/coding-standard": "^13.0",
3333
"php-parallel-lint/php-parallel-lint": "^1.3",
3434
"phpstan/phpstan": "^1.4",
35-
"phpunit/phpunit": ">=7.5"
35+
"phpunit/phpunit": ">=7.5",
36+
"phpstan/phpdoc-parser": "1.5.*"
3637
},
3738
"scripts": {
3839
"phpstan": "phpstan analyse ./src ./tests --level=max --no-progress -c phpstan.neon",

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ parameters:
6565
count: 1
6666
path: src/CsvReader.php
6767

68-
-
69-
message: "#^PHPDoc tag @param has invalid value \\(\\$fileName\\)\\: Unexpected token \"\\$fileName\", expected type at offset 18$#"
70-
count: 1
71-
path: src/CsvReader.php
72-
7368
-
7469
message: "#^Parameter \\#1 \\$header of static method Keboola\\\\Csv\\\\UTF8BOMHelper\\:\\:detectAndRemoveBOM\\(\\) expects array, array\\|false\\|null given\\.$#"
7570
count: 1

src/LineBreaksHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public static function detectLineBreaks($sample, $enclosure, $escapedBy)
5353
*/
5454
public static function clearCsvValues($sample, $enclosure, $escapedBy)
5555
{
56+
if (empty($enclosure)) {
57+
return $sample;
58+
}
59+
5660
// Usually an enclosure character is escaped by doubling it, however, the escapeBy can be used
5761
$doubleEnclosure = $enclosure . $enclosure;
5862
$escapedEnclosure = empty($escapedBy) ? $doubleEnclosure : $escapedBy . $enclosure;

tests/LineBreaksHelperTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public function getDataSet()
5050
"\n",
5151
];
5252

53+
yield 'empty-enclosure' => [
54+
'',
55+
'',
56+
'col1|col2',
57+
'col1|col2',
58+
"\n",
59+
];
60+
5361
yield 'empty-escaped-by' => [
5462
'"',
5563
'\\',
@@ -59,6 +67,20 @@ public function getDataSet()
5967
];
6068

6169
foreach ($lineEnds as $prefix => $lineEnd) {
70+
yield "$prefix-empty-enclosure" => [
71+
'',
72+
'',
73+
implode($lineEnd, [
74+
'col1,col2',
75+
'abc,def',
76+
]),
77+
implode($lineEnd, [
78+
'col1,col2',
79+
'abc,def',
80+
]),
81+
$lineEnd,
82+
];
83+
6284
yield "$prefix-simple" => [
6385
'"',
6486
'',

0 commit comments

Comments
 (0)