8000 [Routing] Fix removing aliases pointing to removed route in RouteColl… · symfonyaml/symfony@238894b · GitHub
[go: up one dir, main page]

Skip to content

Commit 238894b

Browse files
committed
[Routing] Fix removing aliases pointing to removed route in RouteCollection::remove()
1 parent 92513d3 commit 238894b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,15 @@ public function get(string $name)
157157
*/
158158
public function remove($name)
159159
{
160-
foreach ((array) $name as $n) {
161-
unset($this->routes[$n], $this->priorities[$n], $this->aliases[$n]);
160+
$names = (array) $name;
161+
foreach ($names as $n) {
162+
unset($this->routes[$n], $this->priorities[$n]);
163+
}
164+
165+
foreach ($this->aliases as $k => $alias) {
166+
if (\in_array($alias->getId(), $names, true)) {
167+
unset($this->aliases[$k]);
168+
}
162169
}
163170
}
164171

src/Symfony/Component/Routing/Tests/RouteCollectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,13 @@ public function testRemove()
225225
$collection1->add('bar', $bar = new Route('/bar'));
226226
$collection->addCollection($collection1);
227227
$collection->add('last', $last = new Route('/last'));
228+
$collection->addAlias('ccc_my_custom_alias', 'foo');
228229

229230
$collection->remove('foo');
230231
$this->assertSame(['bar' => $bar, 'last' => $last], $collection->all(), '->remove() can remove a single route');
231232
$collection->remove(['bar', 'last']);
232233
$this->assertSame([], $collection->all(), '->remove() accepts an array and can remove multiple routes at once');
234+
$this->assertNull($collection->getAlias('ccc_my_custom_alias'));
233235
}
234236

235237
public function testSetHost()

0 commit comments

Comments
 (0)
0