From 53a6ff88f77e47c81e3bcee061fc1cf95cfc8dcb Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 10 Mar 2019 15:36:46 +0100 Subject: [PATCH] [Routing] Fixed XML options resolution --- .../Routing/Loader/XmlFileLoader.php | 3 ++- .../Routing/Tests/Fixtures/localized/utf8.xml | 13 ++++++++++++ .../Tests/Loader/XmlFileLoaderTest.php | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/localized/utf8.xml diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index e56add97a34f..444a08a77685 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -208,6 +208,7 @@ private function parseConfigs(\DOMElement $node, $path) $options = []; $condition = null; + /** @var \DOMElement $n */ foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) { if ($node !== $n->parentNode) { continue; @@ -226,7 +227,7 @@ private function parseConfigs(\DOMElement $node, $path) $requirements[$n->getAttribute('key')] = trim($n->textContent); break; case 'option': - $options[$n->getAttribute('key')] = trim($n->textContent); + $options[$n->getAttribute('key')] = XmlUtils::phpize(trim($n->textContent)); break; case 'condition': $condition = trim($n->textContent); diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/localized/utf8.xml b/src/Symfony/Component/Routing/Tests/Fixtures/localized/utf8.xml new file mode 100644 index 000000000000..95aff20cfee1 --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/localized/utf8.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php index 66588e7e900a..9a061b295afb 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php @@ -83,6 +83,26 @@ public function testLoadWithImport() } } + public function testUtf8Route() + { + $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized'])); + $routeCollection = $loader->load('utf8.xml'); + $routes = $routeCollection->all(); + + $this->assertCount(2, $routes, 'Two routes are loaded'); + $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes); + + $utf8Route = $routeCollection->get('app_utf8'); + + $this->assertSame('/utf8', $utf8Route->getPath()); + $this->assertTrue($utf8Route->getOption('utf8'), 'Must be utf8'); + + $noUtf8Route = $routeCollection->get('app_no_utf8'); + + $this->assertSame('/no-utf8', $noUtf8Route->getPath()); + $this->assertFalse($noUtf8Route->getOption('utf8'), 'Must not be utf8'); + } + /** * @expectedException \InvalidArgumentException * @dataProvider getPathsToInvalidFiles