-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[DependencyInjection] Ensure Definition::getTags() contains a list of attributes for each tag
#62683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
nicolas-grekas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 6.4? I think this was mostly undefined, but indeed it's better to define the behavior.
src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
Outdated
Show resolved
Hide resolved
|
We can also fix the bug directly where it was introduced: diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
index 00fdaaf2b47..751f8a535c8 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
@@ -81,6 +81,7 @@ trait PriorityTaggedServiceTrait
$phpAttributes = [];
}
+ $attributes = array_values($attributes);
for ($i = 0; $i < \count($attributes); ++$i) {
if (!($attribute = $attributes[$i]) && $phpAttributes) {
array_splice($attributes, $i--, 1, $phpAttributes);
|
… attributes for each tag
Definition::getTags() contains a list of attributes for each tag
| ; | ||
| $container->register(ControllerArguments::class, ControllerArguments::class) | ||
| ->setTags(['controller.service_arguments']) | ||
| ->setTags(['controller.service_arguments' => []]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me to be a breaking change if people inject random values via
Definition::setTags() and expect to retrieve these values with Definition::getTags().
|
Replaced by #62685 We can improve the type of |
…n tag attributes are not a list (GromNaN) This PR was merged into the 7.3 branch. Discussion ---------- [DependencyInjection] Fix `PriorityTaggedServiceTrait` when tag attributes are not a list | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Alternative to #62683 Ensure the attributes of the tag are in a list before iterating on them using sequential indexes. > In symfony/monolog-bundle#485, the tag attributes are filtered, which generates gaps in the keys. The PR mentioned above causes MonologBundle to fail. This can be fixed by symfony/monolog-bundle#563. However I believe the issue should also be addressed in Symfony. Commits ------- 5a4a036 [DependencyInjection] Fix PriorityTaggedServiceTrait when tag attributes are not a list
In #62329, we assume that the response of
Definition::getTags()has the typearray<string, list<array>>. However, when usingDefinition::setTags(), we can set anyarrayvalue without validation.In symfony/monolog-bundle#485, the tag attributes are filtered, which generates gaps in the keys. The PR mentioned above causes MonologBundle to fail. This can be fixed by symfony/monolog-bundle#563. However I believe the issue should also be addressed in Symfony.
This PR targets 7.3 because the bug is in this version, but the patch can be applied in 6.4.Switched to 6.4