Skip to content

Commit fcb11c7

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: [Routing] Fix removing aliases pointing to removed route in RouteCollection::remove()
2 parents 2a89505 + ce95b87 commit fcb11c7

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
@@ -147,8 +147,15 @@ public function get(string $name): ?Route
147147
*/
148148
public function remove(string|array $name)
149149
{
150-
foreach ((array) $name as $n) {
151-
unset($this->routes[$n], $this->priorities[$n], $this->aliases[$n]);
150+
$names = (array) $name;
151+
foreach ($names as $n) {
152+
unset($this->routes[$n], $this->priorities[$n]);
153+
}
154+
155+
foreach ($this->aliases as $k => $alias) {
156+
if (\in_array($alias->getId(), $names, true)) {
157+
unset($this->aliases[$k]);
158+
}
152159
}
153160
}
154161

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)