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 7b4d4b6

Browse filesBrowse files
committed
fix handling of nullable XML attributes
As @Tobion pointed out in #11394, true and 1 are valid values in boolean XML attributes. The XmlFileLoader didn't handle 1 values properly.
1 parent 65862c9 commit 7b4d4b6
Copy full SHA for 7b4d4b6

File tree

3 files changed

+38
-1
lines changed
Filter options

3 files changed

+38
-1
lines changed

‎src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/XmlFileLoader.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private function parseConfigs(\DOMElement $node, $path)
215215
foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) {
216216
switch ($n->localName) {
217217
case 'default':
218-
if ($n->hasAttribute('xsi:nil') && 'true' == $n->getAttribute('xsi:nil')) {
218+
if ($this->isElementValueNull($n)) {
219219
$defaults[$n->getAttribute('key')] = null;
220220
} else {
221221
$defaults[$n->getAttribute('key')] = trim($n->textContent);
@@ -235,4 +235,15 @@ private function parseConfigs(\DOMElement $node, $path)
235235

236236
return array($defaults, $requirements, $options);
237237
}
238+
239+
private function isElementValueNull(\DOMElement $element)
240+
{
241+
$namespaceUri = 'http://www.w3.org/2001/XMLSchema-instance';
242+
243+
if (!$element->hasAttributeNS($namespaceUri, 'nil')) {
244+
return false;
245+
}
246+
247+
return 'true' === $element->getAttributeNS($namespaceUri, 'nil') || '1' === $element->getAttributeNS($namespaceUri, 'nil');
248+
}
238249
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
5+
6+
<route id="blog_show" path="/blog/{slug}">
7+
<default key="foo" xsi:nil="true" />
8+
<default key="bar" xsi:nil="1" />
9+
<default key="foobar" xsi:nil="false">foo</default>
10+
<default key="baz" xsi:nil="0">bar</default>
11+
</route>
12+
</routes>

‎src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,18 @@ public function testDocTypeIsNotAllowed()
124124
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
125125
$loader->load('withdoctype.xml');
126126
}
127+
128+
public function testNullValues()
129+
{
130+
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
131+
$routeCollection = $loader->load('null_values.xml');
132+
$route = $routeCollection->get('blog_show');
133+
134+
$this->assertTrue($route->hasDefault('foo'));
135+
$this->assertNull($route->getDefault('foo'));
136+
$this->assertTrue($route->hasDefault('bar'));
137+
$this->assertNull($route->getDefault('bar'));
138+
$this->assertEquals('foo', $route->getDefault('foobar'));
139+
$this->assertEquals('bar', $route->getDefault('baz'));
140+
}
127141
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.