8000
We read every piece of feedback, and take your input very seriously.
1 parent 3bd2e01 commit 3ae826aCopy full SHA for 3ae826a
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
@@ -216,6 +216,12 @@ private function parseDefinition($id, $service, $file)
216
$name = $tag['name'];
217
unset($tag['name']);
218
219
+ foreach ($tag as $attribute => $value) {
220
+ if (!is_scalar($value)) {
221
+ throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s" in %s.', $id, $name, $file));
222
+ }
223
224
+
225
$definition->addTag($name, $tag);
226
}
227
tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/badtag3.yml
@@ -0,0 +1,6 @@
1
+services:
2
+ foo_service:
3
+ class: FooClass
4
+ tags:
5
+ # tag-attribute is not a scalar
6
+ - { name: foo, foo: { foo: foo, bar: bar } }
tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php
@@ -185,4 +185,16 @@ public function testTagWithoutNameThrowsException()
185
$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');
186
187
188
189
+ public function testTagWithAttributeArrayThrowsException()
190
+ {
191
+ $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
192
+ try {
193
+ $loader->load('badtag3.yml');
194
+ $this->fail('->load() should throw an exception when a tag-attribute is not a scalar');
195
+ } catch (\Exception $e) {
196
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if a tag-attribute is not a scalar');
197
+ $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');
198
199
200