diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 24cf257105..5cbc8e7af6 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -267,6 +267,8 @@ class XmlEncoder extends AbstractEncoder */ protected function isElementNameValid($name) { - return $name && strpos($name, ' ') === false && preg_match('|^\w+$|', $name); + return $name && + false === strpos($name, ' ') && + preg_match('#^[\pL_][\pL0-9._-]+$#ui', $name); } } diff --git a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php index 73a0a8daef..45cfc4fea0 100644 --- a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php +++ b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php @@ -53,6 +53,25 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $this->encoder->encode($obj, 'xml')); } + public function testElementNameValid() + { + $obj = new ScalarDummy; + $obj->xmlFoo = array( + 'foo-bar' => '', + 'foo_bar' => '', + 'föo_bär' => '', + ); + + $expected = ''."\n". + ''. + ''. + ''. + ''. + ''."\n"; + + $this->assertEquals($expected, $this->encoder->encode($obj, 'xml')); + } + public function testEncodeSimpleXML() { $xml = simplexml_load_string('Peter');