8000 merged 2.0 · cbaudoux/symfony@d2fd9ce · GitHub
[go: up one dir, main page]

Skip to content

Commit d2fd9ce

Browse files
committed
merged 2.0
2 parents d9fa1b9 + 098b934 commit d2fd9ce

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ private function parseDefinition($id, $service, $file)
211211
$name = $tag['name'];
212212
unset($tag['name']);
213213

214+
foreach ($tag as $attribute => $value) {
215+
if (!is_scalar($value)) {
216+
throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s" in %s.', $id, $name, $file));
217+
}
218+
}
219+
214220
$definition->addTag($name, $tag);
215221
}
216222
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 } }

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,16 @@ public function testTagWithoutNameThrowsException()
196196
$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');
197197
}
198198
}
199+
200+
public function testTagWithAttributeArrayThrowsException()
201+
{
202+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
203+
try {
204+
$loader->load('badtag3.yml');
205+
$this->fail('->load() should throw an exception when a tag-attribute is not a scalar');
206+
} catch (\Exception $e) {
207+
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if a tag-attribute is not a scalar');
208+
$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');
209+
}
210+
}
199211
}

0 commit comments

Comments
 (0)
0