8000 XmlFileLoader: enforce tags to have a name · symfony/symfony@5ef1f26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ef1f26

Browse files
committed
XmlFileLoader: enforce tags to have a name
1 parent 423f83f commit 5ef1f26

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
</xsd:complexType>
9898

9999
<xsd:complexType name="tag">
100-
<xsd:attribute name="name" type="xsd:string" />
100+
<xsd:attribute name="name" type="xsd:string" use="required" />
101101
<xsd:anyAttribute namespace="##any" processContents="lax" />
102102
</xsd:complexType>
103103

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>

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

Lines changed: 15 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;
@@ -207,6 +208,20 @@ public function testParsesTags()
207208
}
208209
}
209210

211+
public function testParseTagsWithoutName()
212+
{
213+
try {
214+
$container = new ContainerBuilder();
215+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath . '/xml'));
216+
$loader->load('invalid_tag.xml');
217+
218+
$this->fail('The XmlFileLoader is expected to throw an exception when the name attribute is missing or a tag.');
219+
} catch (InvalidArgumentException $e) {
220+
$this->assertInstanceOf('\InvalidArgumentException', $e->getPrevious());
221+
$this->assertRegExp("/The attribute 'name' is required but missing/", $e->getPrevious()->getMessage());
222+
}
223+
}
224+
210225
public function testConvertDomElementToArray()
211226
{
212227
$doc = new \DOMDocument('1.0');

0 commit comments

Comments
 (0)
0