From af369aee64c1bd61f144835d146e94ca88a3543d Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 11 Oct 2013 00:23:27 +0200 Subject: [PATCH] [Yaml] Fixed the escaping of strings starting with a dash when dumping Dashes need to be escaped in character sets in regexes as they are used to specify a range otherwise. Refs #9039 --- src/Symfony/Component/Yaml/Escaper.php | 2 +- src/Symfony/Component/Yaml/Tests/InlineTest.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Yaml/Escaper.php b/src/Symfony/Component/Yaml/Escaper.php index f77545db95632..7409ebfe2c366 100644 --- a/src/Symfony/Component/Yaml/Escaper.php +++ b/src/Symfony/Component/Yaml/Escaper.php @@ -71,7 +71,7 @@ public static function escapeWithDoubleQuotes($value) */ public static function requiresSingleQuoting($value) { - return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ - ? | < > = ! % @ ` ]/x', $value); + return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value); } /** diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 04e9d4df80985..dc8ab7061b9e4 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Yaml\Tests; -use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Inline; class InlineTest extends \PHPUnit_Framework_TestCase @@ -31,11 +30,11 @@ public function testDump() $this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml)); } - foreach ($this->getTestsForParse() as $yaml => $value) { + foreach ($this->getTestsForParse() as $value) { $this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency'); } - foreach ($testsForDump as $yaml => $value) { + foreach ($testsForDump as $value) { $this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency'); } } @@ -205,6 +204,9 @@ protected function getTestsForDump() "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', + "'-dash'" => '-dash', + "'-'" => '-', + // sequences '[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'),