Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Symfony/Component/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ public function addNamePrefix(string $prefix)
}

foreach ($this->aliases as $name => $alias) {
$prefixedAliases[$prefix.$name] = $alias->withId($prefix.$alias->getId());
$targetId = $alias->getId();

if (isset($this->routes[$targetId]) || isset($this->aliases[$targetId])) {
$targetId = $prefix.$targetId;
}

$prefixedAliases[$prefix.$name] = $alias->withId($targetId);
}

$this->routes = $prefixedRoutes;
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,18 @@ public function testAddWithPriorityAndPrefix()

$this->assertSame($expected, $collection3->all());
}

public function testAddNamePrefixDoesNotBreakExternalAliases()
{
$collection = new RouteCollection();
$collection->add('local_route', new Route('/local'));
$collection->addAlias('alias_to_local', 'local_route');
$collection->addAlias('alias_to_external', 'external_route');
$collection->addNamePrefix('prefix_');

$aliases = $collection->getAliases();

$this->assertEquals('prefix_local_route', $aliases['prefix_alias_to_local']->getId(), 'Alias to local route should have its target prefixed');
$this->assertEquals('external_route', $aliases['prefix_alias_to_external']->getId(), 'Alias to external route should NOT have its target prefixed');
}
}