Skip to content

[DependencyInjection] Fix bug when tag name is a text node #48449

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

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
$tags = $this->getChildren($service, 'tag');

foreach ($tags as $tag) {
if ('' === $tagName = $tag->hasChildNodes() || '' === $tag->nodeValue ? $tag->getAttribute('name') : $tag->nodeValue) {
if ('' === $tagName = $tag->childElementCount || '' === $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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
other-option="lorem"
an_other-option="ipsum"
/>
<tag some-option="cat"
some_option="ciz"
other-option="lorem"
an_other-option="ipsum">bar_tag</tag>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,17 @@ public function testParsesIteratorArgument()
$this->assertEquals([new IteratorArgument(['k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')]), new IteratorArgument([])], $lazyDefinition->getArguments(), '->load() parses lazy arguments');
}

public function testParsesTags()
/**
* @testWith ["foo_tag"]
* ["bar_tag"]
*/
public function testParsesTags(string $tag)
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services10.xml');

$services = $container->findTaggedServiceIds('foo_tag');
$services = $container->findTaggedServiceIds($tag);
$this->assertCount(1, $services);

foreach ($services as $id => $tagAttributes) {
Expand Down