Skip to content

Commit e1e0762

Browse files
bug #33744 [DI] Add CSV env var processor tests / support PHP 7.4 (ro0NL)
This PR was merged into the 4.3 branch. Discussion ---------- [DI] Add CSV env var processor tests / support PHP 7.4 | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #... <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Similar as #32051 Commits ------- 82f341864c [DI] Add CSV env var processor tests
2 parents 581f30c + ed844eb commit e1e0762

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

EnvVarProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function getEnv($prefix, $name, \Closure $getEnv)
236236
}
237237

238238
if ('csv' === $prefix) {
239-
return str_getcsv($env);
239+
return str_getcsv($env, ',', '"', \PHP_VERSION_ID >= 70400 ? '' : '\\');
240240
}
241241

242242
if ('trim' === $prefix) {

Tests/EnvVarProcessorTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,37 @@ public function testRequireFile()
478478

479479
$this->assertEquals('foo', $result);
480480
}
481+
482+
/**
483+
* @dataProvider validCsv
484+
*/
485+
public function testGetEnvCsv($value, $processed)
486+
{
487+
$processor = new EnvVarProcessor(new Container());
488+
489+
$result = $processor->getEnv('csv', 'foo', function ($name) use ($value) {
490+
$this->assertSame('foo', $name);
491+
492+
return $value;
493+
});
494+
495+
$this->assertSame($processed, $result);
496+
}
497+
498+
public function validCsv()
499+
{
500+
$complex = <<<'CSV'
501+
,"""","foo""","\""",\,foo\
502+
CSV;
503+
504+
return [
505+
['', [null]],
506+
[',', ['', '']],
507+
['1', ['1']],
508+
['1,2," 3 "', ['1', '2', ' 3 ']],
509+
['\\,\\\\', ['\\', '\\\\']],
510+
[$complex, \PHP_VERSION_ID >= 70400 ? ['', '"', 'foo"', '\\"', '\\', 'foo\\'] : ['', '"', 'foo"', '\\"",\\,foo\\']],
511+
[null, null],
512+
];
513+
}
481514
}

0 commit comments

Comments
 (0)