Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 82f3418

Browse filesBrowse files
committed
[DI] Add CSV env var processor tests
1 parent fbfdebc commit 82f3418
Copy full SHA for 82f3418

File tree

2 files changed

+34
-1
lines changed
Filter options

2 files changed

+34
-1
lines changed

‎src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
+1-1Lines 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) {

‎src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php
+33Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.