10000 [DependencyInjection] Fix "url" env var processor behavior when the u… · symfony/symfony@2876cf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2876cf9

Browse files
committed
[DependencyInjection] Fix "url" env var processor behavior when the url has no path
1 parent 09fe733 commit 2876cf9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ public function getEnv($prefix, $name, \Closure $getEnv)
255255
'fragment' => null,
256256
];
257257

258-
// remove the '/' separator
259-
$parsedEnv['path'] = '/' === $parsedEnv['path'] ? null : substr($parsedEnv['path'], 1);
258+
if (null !== $parsedEnv['path']) {
259+
// remove the '/' separator
260+
$parsedEnv['path'] = '/' === $parsedEnv['path'] ? null : substr($parsedEnv['path'], 1);
261+
}
260262

261263
return $parsedEnv;
262264
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,26 @@ public function testGetEnvInvalidPrefixWithDefault()
610610
return null;
611611
});
612612
}
613+
614+
/**
615+
* @dataProvider provideGetEnvUrlPath
616+
*/
617+
public function testGetEnvUrlPath(?string $expected, string $url)
618+
{
619+
$this->assertSame($expected, (new EnvVarProcessor(new Container()))->getEnv('url', 'foo', static function () use ($url): string {
620+
return $url;
621+
})['path']);
622+
}
623+
624+
public function provideGetEnvUrlPath()
625+
{
626+
return [
627+
[null, 'https://symfony.com'],
628+
[null, 'https://symfony.com/'],
629+
['/', 'https://symfony.com//'],
630+
['blog', 'https://symfony.com/blog'],
631+
['blog/', 'https://symfony.com/blog/'],
632+
['blog//', 'https://symfony.com/blog//'],
633+
];
634+
}
613635
}

0 commit comments

Comments
 (0)
0