8000 bug #9274 [Yaml] Fixed the escaping of strings starting with a dash w… · symfony/symfony@b599598 · GitHub
[go: up one dir, main page]

Skip to content

Commit b599598

Browse files
committed
bug #9274 [Yaml] Fixed the escaping of strings starting with a dash when dumping (stof)
This PR was merged into the 2.2 branch. Discussion ---------- [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. It fixes the dumper bug reported in #9039 (the parsing issue is not fix here) | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | partially #9039 | License | MIT | Doc PR | n/a Commits ------- af369ae [Yaml] Fixed the escaping of strings starting with a dash when dumping
2 parents 9f88673 + af369ae commit b599598

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Symfony/Component/Yaml/Escaper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function escapeWithDoubleQuotes($value)
7171
*/
7272
public static function requiresSingleQuoting($value)
7373
{
74-
return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ - ? | < > = ! % @ ` ]/x', $value);
74+
return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
7575
}
7676

7777
/**

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Yaml\Tests;
1313

14-
use Symfony\Component\Yaml\Yaml;
1514
use Symfony\Component\Yaml\Inline;
1615

1716
class InlineTest extends \PHPUnit_Framework_TestCase
@@ -31,11 +30,11 @@ public function testDump()
3130
$this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
3231
}
3332

34-
foreach ($this->getTestsForParse() as $yaml => $value) {
33+
foreach ($this->getTestsForParse() as $value) {
3534
$this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency');
3635
}
3736

38-
foreach ($testsForDump as $yaml => $value) {
37+
foreach ($testsForDump as $value) {
3938
$this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency');
4039
}
4140
}
@@ -205,6 +204,9 @@ protected function getTestsForDump()
205204

206205
"'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'',
207206

207+
"'-dash'" => '-dash',
208+
"'-'" => '-',
209+
208210
// sequences
209211
'[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12),
210212
'[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'),

0 commit comments

Comments
 (0)
0