File tree 2 files changed +19
-1
lines changed
src/Symfony/Component/DependencyInjection
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -469,7 +469,8 @@ protected function getEnv($name)
469
469
return $ this ->envCache [$ name ];
470
470
}
471
471
if (!$ this ->has ($ id = 'container.env_var_processors_locator ' )) {
472
- $ this ->set ($ id , new ServiceLocator (array ()));
472
+ // Prevent an infinite loop, because set() call getRemovedIds() that may call getEnv()
473
+ $ this ->services [$ id ] = new ServiceLocator (array ());
473
474
}
474
475
if (!$ this ->getEnv ) {
475
476
$ this ->getEnv = new \ReflectionMethod ($ this , __FUNCTION__ );
Original file line number Diff line number Diff line change @@ -538,6 +538,23 @@ public function testReplacingAPreDefinedServiceIsDeprecated()
538
538
539
539
$ this ->assertSame ($ bar , $ c ->get ('bar ' ), '->set() replaces a pre-defined service ' );
540
540
}
541
+
542
+ public function testNoInfiniteLoopInGetEnv ()
543
+ {
544
+ $ _ENV ['bar ' ] = 'hello ' ;
545
+ $ this ->assertCount (1 , (new RemovedIdsCallGetEnvContainer ())->getRemovedIds ());
546
+ unset($ _ENV ['bar ' ]);
547
+ }
548
+ }
549
+
550
+ class RemovedIdsCallGetEnvContainer extends Container
551
+ {
552
+ public function getRemovedIds ()
553
+ {
554
+ return array (
555
+ 'foo. ' .$ this ->getEnv ('bar ' ) => true ,
556
+ );
557
+ }
541
558
}
542
559
543
560
class ProjectServiceContainer extends Container
You can’t perform that action at this time.
0 commit comments