8000 merged branch phreaknerd/fix_issue_#3251_for_2.0 (PR #3926) · jeremymarc/symfony@a4ea77b · GitHub
[go: up one dir, main page]

Skip to content

Commit a4ea77b

Browse files
committed
merged branch phreaknerd/fix_issue_#3251_for_2.0 (PR symfony#3926)
Commits ------- 3ae826a Fix issue symfony#3251: Check attribute type of service tags Discussion ---------- Fix issue symfony#3251: Check attribute type of service tags The attributes of service tags have to be of a scalar type. It was possible to add arrays here with yaml-configuration.
2 parents 3bd2e01 + 3ae826a commit a4ea77b

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

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+
219225
$definition->addTag($name, $tag);
220226
}
221227
}
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 } }

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@ public function testTagWithoutNameThrowsException()
185185
$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');
186186
}
187187
}
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+
}
188200
}

0 commit comments

Comments
 (0)
0