Skip to content

Commit 990b51b

Browse files
committed
bug #40629 [DependencyInjection] Fix "url" env var processor behavior when the url has no path (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Fix "url" env var processor behavior when the url has no path | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Before: ```yaml MY_URL_ENV_VAR=http://symfony.com %env(key:path:url:MY_URL_ENV_VAR)% --> false ``` After: ```yaml MY_URL_ENV_VAR=http://symfony.com %env(key:path:url:MY_URL_ENV_VAR)% --> null ``` Returning `false` for the path prevents me from using the `default` env var processor that is triggered only for `''` and `null`. (`%env(default:my_fallback_param:key:path:url:MY_URL_ENV_VAR)%`) BTW, with PHP 8, it actually works because `substr(null, 1)` behavior changed (see https://3v4l.org/oHf6l). Commits ------- 2876cf9 [DependencyInjection] Fix "url" env var processor behavior when the url has no path
2 parents 2ceb35a + 2876cf9 commit 990b51b

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)
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