-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[6.2] [DI] Node Value ignored in XMLFileLoader #48445
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
Comments
I guess that code misses parenthesis around the |
Can you please implement what @stof suggests @BrandonlinU and submit it as a PR on 6.2? |
Sure, give me a moment to make the pull request... |
Well... I have bad news: After update the code with the following code if ('' === $tagName = ($tag->hasChildNodes() || '' === $tag->nodeValue) ? $tag->getAttribute('name') : $tag->nodeValue) {
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', (string) $service->getAttribute('id'), $file));
} still does not pass the tests, because |
Workaround for symfony/symfony#48445
… (BrandonlinU) This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [DependencyInjection] Fix bug when tag name is a text node | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48445 | License | MIT Following the discussion in the ticket, I added a test for a tag without name attribute and content inside the tag for the name. I use `$tag->childElementCount !== 0` instead of `$tag->hasChildNode()` to detect if a `<attribute>` tag is present in the tag definition, or is only the name of the tag. Commits ------- b9337f1 [DependencyInjection] Fix bug when tag name is a text node
Symfony version(s) affected
6.2.0
Description
After update to Symfony 6.2, the new changes to support the array tag attributes introduced in #47364 throw an exception when it load a service tag with the name in the inner content of the tag.
How to reproduce
symfony/dependency-injection
andsymfony/config
dependencies.index.php
file with the following content:service.xml
with a service description with a tag, as the following.index.php
script.Possible Solution
It looks like that in the XmlFileLoader tries to extract the tagName incorrectly, because the
$tag->hasChildNodes()
return a boolean, and not an string, and when tries to extract thenodeValue
, it extracts the attribute name instead, causing the error.symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
Lines 339 to 341 in 3444c1e
I think that with the following code, that tries to extract the nodeValue and if it is not possible tries to get the attribute name from the XML tag, should solve the error.
Additional Context
The exception throw is the following:
The text was updated successfully, but these errors were encountered: