8000 Break infinite loop while resolving aliases · symfony/symfony@acbde50 · GitHub
[go: up one dir, main page]

Skip to content

Commit acbde50

Browse files
chxfabpot
authored andcommitted
Break infinite loop while resolving aliases
1 parent 6a62318 commit acbde50

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
1516
use Symfony\Component\DependencyInjection\Reference;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718

@@ -84,7 +85,12 @@ private function processArguments(array $arguments)
8485
*/
8586
private function getDefinitionId($id)
8687
{
88+
$seen = array();
8789
while ($this->container->hasAlias($id)) {
90+
if (isset($seen[$id])) {
91+
throw new ServiceCircularReferenceException($id, array_keys($seen));
92+
}
93+
$seen[$id] = true;
8894
$id = (string) $this->container->getAlias($id);
8995
}
9096

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public function testProcessRecursively()
4848
$this->assertEquals('foo', (string) $arguments[0]);
4949
}
5050

51+
/**
52+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
53+
*/
54+
public function testAliasCircularReference()
55+
{
56+
$container = new ContainerBuilder();
57+
$container->setAlias('bar', 'foo');
58+
$container->setAlias('foo', 'bar');
59+
$this->process($container);
60+
}
61+
5162
protected function process(ContainerBuilder $container)
5263
{
5364
$pass = new ResolveReferencesToAliasesPass();

0 commit comments

Comments
 (0)
0