From 2876cf9cc6af8667611980d2796e5f0705bba3b9 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 29 Mar 2021 15:11:05 +0200 Subject: [PATCH] [DependencyInjection] Fix "url" env var processor behavior when the url has no path --- .../DependencyInjection/EnvVarProcessor.php | 6 +++-- .../Tests/EnvVarProcessorTest.php | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php index 8792cd64e7bae..d9809959d5895 100644 --- a/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php +++ b/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php @@ -255,8 +255,10 @@ public function getEnv($prefix, $name, \Closure $getEnv) 'fragment' => null, ]; - // remove the '/' separator - $parsedEnv['path'] = '/' === $parsedEnv['path'] ? null : substr($parsedEnv['path'], 1); + if (null !== $parsedEnv['path']) { + // remove the '/' separator + $parsedEnv['path'] = '/' === $parsedEnv['path'] ? null : substr($parsedEnv['path'], 1); + } return $parsedEnv; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php index ab5f24b2ecba2..45a64e4f8e059 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php @@ -610,4 +610,26 @@ public function testGetEnvInvalidPrefixWithDefault() return null; }); } + + /** + * @dataProvider provideGetEnvUrlPath + */ + public function testGetEnvUrlPath(?string $expected, string $url) + { + $this->assertSame($expected, (new EnvVarProcessor(new Container()))->getEnv('url', 'foo', static function () use ($url): string { + return $url; + })['path']); + } + + public function provideGetEnvUrlPath() + { + return [ + [null, 'https://symfony.com'], + [null, 'https://symfony.com/'], + ['/', 'https://symfony.com//'], + ['blog', 'https://symfony.com/blog'], + ['blog/', 'https://symfony.com/blog/'], + ['blog//', 'https://symfony.com/blog//'], + ]; + } }