From 82f341864c28ba69aef1e28f615bf112203fce8c Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sat, 28 Sep 2019 11:54:52 +0200 Subject: [PATCH] [DI] Add CSV env var processor tests --- .../DependencyInjection/EnvVarProcessor.php | 2 +- .../Tests/EnvVarProcessorTest.php | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php index 7202cd7a9881f..9231cf48c5fb5 100644 --- a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php +++ b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php @@ -236,7 +236,7 @@ public function getEnv($prefix, $name, \Closure $getEnv) } if ('csv' === $prefix) { - return str_getcsv($env); + return str_getcsv($env, ',', '"', \PHP_VERSION_ID >= 70400 ? '' : '\\'); } if ('trim' === $prefix) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php index b8bc6da05cb67..c960c2f1ada2c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php @@ -478,4 +478,37 @@ public function testRequireFile() $this->assertEquals('foo', $result); } + + /** + * @dataProvider validCsv + */ + public function testGetEnvCsv($value, $processed) + { + $processor = new EnvVarProcessor(new Container()); + + $result = $processor->getEnv('csv', 'foo', function ($name) use ($value) { + $this->assertSame('foo', $name); + + return $value; + }); + + $this->assertSame($processed, $result); + } + + public function validCsv() + { + $complex = <<<'CSV' +,"""","foo""","\""",\,foo\ +CSV; + + return [ + ['', [null]], + [',', ['', '']], + ['1', ['1']], + ['1,2," 3 "', ['1', '2', ' 3 ']], + ['\\,\\\\', ['\\', '\\\\']], + [$complex, \PHP_VERSION_ID >= 70400 ? ['', '"', 'foo"', '\\"', '\\', 'foo\\'] : ['', '"', 'foo"', '\\"",\\,foo\\']], + [null, null], + ]; + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy