8000 Fix issue #3251: Check attribute type of service tags · jeremymarc/symfony@3ae826a · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ae826a

Browse files
committed
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.
1 parent 3bd2e01 commit 3ae826a

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