Skip to content

Commit c85a696

Browse files
committed
minor #61507 [Security] Preserve ordering of roles in RoleHierarchy (nicolas-grekas)
This PR was merged into the 7.4 branch. Discussion ---------- [Security] Preserve ordering of roles in RoleHierarchy | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT As suggested in #61057 /cc `@simonjamain` Commits ------- d4338b1 [Security] Preserve ordering of roles in RoleHierarchy
2 parents cd7cfec + d4338b1 commit c85a696

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Symfony/Component/Security/Core/Role/RoleHierarchy.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ protected function buildRoleMap(): void
5454
$this->map[$main] = $roles;
5555
$visited = [];
5656
$additionalRoles = $roles;
57-
while ($role = array_pop($additionalRoles)) {
57+
while (null !== $role = key($additionalRoles)) {
58+
$role = $additionalRoles[$role];
59+
5860
if (!isset($this->hierarchy[$role])) {
61+
next($additionalRoles);
5962
continue;
6063
}
6164

@@ -68,6 +71,8 @@ protected function buildRoleMap(): void
6871
foreach (array_diff($this->hierarchy[$role], $visited) as $additionalRole) {
6972
$additionalRoles[] = $additionalRole;
7073
}
74+
75+
next($additionalRoles);
7176
}
7277

7378
$this->map[$main] = array_unique($this->map[$main]);

0 commit comments

Comments
 (0)