10000 bug #52806 [Routing] Fix removing aliases pointing to removed route i… · symfony/symfony@ce95b87 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce95b87

Browse files
bug #52806 [Routing] Fix removing aliases pointing to removed route in RouteCollection::remove() (fancyweb)
This PR was merged into the 5.4 branch. Discussion ---------- [Routing] Fix removing aliases pointing to removed route in `RouteCollection::remove()` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | | Issues | #52802 | License | MIT When a route is removed from the collection, we want to remove all aliases pointing to it. The implementation is flawed because the `$aliases` array is indexed by the alias name, and not by the route since several aliases can point to the same route. It'll fix the related issue because added FQCN aliases will be correctly removed when `PrefixTrait::addPrefix()` removes the route before reading it for each locale. Commits ------- 238894b [Routing] Fix removing aliases pointing to removed route in RouteCollection::remove()
2 parents 92513d3 + 238894b commit ce95b87

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