8000 Fix issue #3251: Check attribute type of service tags by phreaknerd · Pull Request #3926 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix issue #3251: Check attribute type of service tags #3926

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
Apr 13, 2012
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 @@ -216,6 +216,12 @@ private function parseDefinition($id, $service, $file)
$name = $tag['name'];
unset($tag['name']);

foreach ($tag as $attribute => $value) {
if (!is_scalar($value)) {
throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s" in %s.', $id, $name, $file));
}
}

$definition->addTag($name, $tag);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
foo_service:
class: FooClass
tags:
# tag-attribute is not a scalar
- { name: foo, foo: { foo: foo, bar: bar } }
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,16 @@ public function testTagWithoutNameThrowsException()
$this->assertStringStartsWith('A "tags" entry is missing a "name" key for service ', $e->getMessage(), '->load() throws an InvalidArgumentException if a tag is missing the name key');
}
}

public function testTagWithAttributeArrayThrowsException()
{
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
try {
$loader->load('badtag3.yml');
$this->fail('->load() should throw an exception when a tag-attribute is not a scalar');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if a tag-attribute is not a scalar');
$this->assertStringStartsWith('A "tags" attribute must be of a scalar-type for service ', $e->getMessage(), '->load() throws an InvalidArgumentException if a tag-attribute is not a scalar');
}
}
}
0