Skip to content

Commit 24fb20e

Browse files
Merge branch '2.8' into 3.0
* 2.8: [Process] Fix transient tests for incremental outputs [Console] Add missing `@require` annotation in test Fix merge [appveyor] Fix failure reporting [#17634] move DebugBundle license file backport GlobTest from 2.7 branch Move licenses according to new best practices [FrameworkBundle] Remove unused code in test [2.3] Fixed an undefined variable in Glob::toRegex simplified a test fix container cache key generation [Form] fix option name in upgrade file [Form] fix option name in changelog [Translation] Add resources from fallback locale [DependencyInjection] enforce tags to have a name [YAML] Refine the return value of Yaml::parse() Conflicts: UPGRADE-2.8.md
2 parents e6bb69a + e9f375e commit 24fb20e

File tree

9 files changed

+85
-1
lines changed

9 files changed

+85
-1
lines changed

Loader/XmlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ private function parseDefinition(\DOMElement $service, $file)
226226
$parameters[$name] = XmlUtils::phpize($node->nodeValue);
227227
}
228228

229+
if ('' === $tag->getAttribute('name')) {
230+
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', (string) $service->getAttribute('id'), $file));
231+
}
232+
229233
$definition->addTag($tag->getAttribute('name'), $parameters);
230234
}
231235

Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ private function parseDefinition($id, $service, $file)
254254
throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
255255
}
256256

257+
if (!is_string($tag['name']) || '' === $tag['name']) {
258+
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in %s must be a non-empty string.', $id, $file));
259+
}
260+
257261
$name = $tag['name'];
258262
unset($tag['name']);
259263

Loader/schema/dic/services/services-1.0.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
</xsd:complexType>
104104

105105
<xsd:complexType name="tag">
106-
<xsd:attribute name="name" type="xsd:string" />
106+
<xsd:attribute name="name" type="xsd:string" use="required" />
107107
<xsd:anyAttribute namespace="##any" processContents="lax" />
108108
</xsd:complexType>
109109

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="foo" class="BarClass">
8+
<tag name="" foo="bar" />
9+
</service>
10+
</services>
11+
</container>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="foo" class="BarClass">
8+
<tag foo="bar" />
9+
</service>
10+
</services>
11+
</container>
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 name is an empty string
6+
- { name: '', foo: bar }
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 name is not a string
6+
- { name: [], foo: bar }

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1617
use Symfony\Component\DependencyInjection\Reference;
1718
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1819
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -247,6 +248,27 @@ public function testParsesTags()
247248
}
248249
}
249250

251+
/**
252+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
253+
*/
254+
public function testParseTagsWithoutNameThrowsException()
255+
{
256+
$container = new ContainerBuilder();
257+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
258+
$loader->load('tag_without_name.xml');
259+
}
260+
261+
/**
262+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
263+
* @expectedExceptionMessageRegExp /The tag name for service ".+" in .* must be a non-empty string/
264+
*/
265+
public function testParseTagWithEmptyNameThrowsException()
266+
{
267+
$container = new ContainerBuilder();
268+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
269+
$loader->load('tag_with_empty_name.xml');
270+
}
271+
250272
public function testConvertDomElementToArray()
251273
{
252274
$doc = new \DOMDocument('1.0');

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,26 @@ public function testLoadYamlOnlyWithKeys()
257257
$this->assertEquals(array('manager' => array(array('alias' => 'user'))), $definition->getTags());
258258
}
259259

260+
/**
261+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
262+
* @expectedExceptionMessageRegExp /The tag name for service ".+" in .+ must be a non-empty string/
263+
*/
264+
public function testTagWithEmptyNameThrowsException()
265+
{
266+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
267+
$loader->load('tag_name_empty_string.yml');
268+
}
269+
270+
/**
271+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
272+
* @expectedExceptionMessageREgExp /The tag name for service "\.+" must be a non-empty string/
273+
*/
274+
public function testTagWithNonStringNameThrowsException()
275+
{
276+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
277+
$loader->load('tag_name_no_string.yml');
278+
}
279+
260280
/**
261281
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
262282
*/

0 commit comments

Comments
 (0)