Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit7af5d6c

Browse files
Thomason, JamesThomason, James
Thomason, James
authored and
Thomason, James
committed
Fix stripos(array, string) bug with array env vars
Add failing test for resolving array envFix stripos(array, string) bug with array env varsRemoving empty line to adhere to Coding StandardAdd assertions to tests for Travis CIUse long array syntax to adhere to coding standards
1 parentfb88119 commit7af5d6c

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,16 +1408,18 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
14081408
}
14091409
$envPlaceholders =$baginstanceof EnvPlaceholderParameterBag ?$bag->getEnvPlaceholders() :$this->envPlaceholders;
14101410

1411+
$completed =false;
14111412
foreach ($envPlaceholdersas$env =>$placeholders) {
14121413
foreach ($placeholdersas$placeholder) {
1413-
if (false !==stripos($value,$placeholder)) {
1414+
if (\is_string($value) &&false !==stripos($value,$placeholder)) {
14141415
if (true ===$format) {
14151416
$resolved =$bag->escapeValue($this->getEnv($env));
14161417
}else {
14171418
$resolved =sprintf($format,$env);
14181419
}
14191420
if ($placeholder ===$value) {
14201421
$value =$resolved;
1422+
$completed =true;
14211423
}else {
14221424
if (!is_string($resolved) && !is_numeric($resolved)) {
14231425
thrownewRuntimeException(sprintf('A string value must be composed of strings and/or numbers, but found parameter "env(%s)" of type %s inside string value "%s".',$env,gettype($resolved),$value));
@@ -1426,6 +1428,10 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
14261428
}
14271429
$usedEnvs[$env] =$env;
14281430
$this->envCounters[$env] =isset($this->envCounters[$env]) ?1 +$this->envCounters[$env] :1;
1431+
1432+
if ($completed) {
1433+
break2;
1434+
}
14291435
}
14301436
}
14311437
}

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,49 @@ public function testCompileWithResolveEnv()
665665
putenv('DUMMY_ENV_VAR');
666666
}
667667

668+
publicfunctiontestCompileWithArrayResolveEnv()
669+
{
670+
putenv('ARRAY={"foo":"bar"}');
671+
672+
$container =newContainerBuilder();
673+
$container->setParameter('foo','%env(json:ARRAY)%');
674+
$container->compile(true);
675+
676+
$this->assertSame(array('foo' =>'bar'),$container->getParameter('foo'));
677+
678+
putenv('ARRAY');
679+
}
680+
681+
publicfunctiontestCompileWithArrayAndAnotherResolveEnv()
682+
{
683+
putenv('DUMMY_ENV_VAR=abc');
684+
putenv('ARRAY={"foo":"bar"}');
685+
686+
$container =newContainerBuilder();
687+
$container->setParameter('foo','%env(json:ARRAY)%');
688+
$container->setParameter('bar','%env(DUMMY_ENV_VAR)%');
689+
$container->compile(true);
690+
691+
$this->assertSame(array('foo' =>'bar'),$container->getParameter('foo'));
692+
$this->assertSame('abc',$container->getParameter('bar'));
693+
694+
putenv('DUMMY_ENV_VAR');
695+
putenv('ARRAY');
696+
}
697+
668698
/**
669699
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
670-
* @expectedExceptionMessage A string value must be composed of strings and/or numbers, but found parameter "env(ARRAY)" of type array inside string value "ABC%env(ARRAY)%".
700+
* @expectedExceptionMessage A string value must be composed of strings and/or numbers, but found parameter "env(json:ARRAY)" of type array inside string value "ABCenv_json_ARRAY_
671701
*/
672-
publicfunctiontestCompileWithArrayResolveEnv()
702+
publicfunctiontestCompileWithArrayInStringResolveEnv()
673703
{
674-
$bag =newTestingEnvPlaceholderParameterBag();
675-
$container =newContainerBuilder($bag);
676-
$container->setParameter('foo','%env(ARRAY)%');
677-
$container->setParameter('bar','ABC %env(ARRAY)%');
704+
putenv('ARRAY={"foo":"bar"}');
705+
706+
$container =newContainerBuilder();
707+
$container->setParameter('foo','ABC %env(json:ARRAY)%');
678708
$container->compile(true);
709+
710+
putenv('ARRAY');
679711
}
680712

681713
/**
@@ -1418,11 +1450,3 @@ public function __construct(A $a)
14181450
{
14191451
}
14201452
}
1421-
1422-
class TestingEnvPlaceholderParameterBagextends EnvPlaceholderParameterBag
1423-
{
1424-
publicfunctionget($name)
1425-
{
1426-
return'env(array)' ===strtolower($name) ?array(123) :parent::get($name);
1427-
}
1428-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp