minor #39769 [Yaml] quote all dumped unicode spaces (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Yaml] quote all dumped unicode spaces

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39767
| License       | MIT
| Doc PR        |

Commits
-------

0028efe8f8 quote all dumped unicode spaces
This commit is contained in:
Fabien Potencier 2021-01-10 09:40:13 +01:00
commit 4cba31e49f
3 changed files with 20 additions and 1 deletions

View File

@ -86,7 +86,7 @@ class Escaper
// Determines if the PHP value contains any single characters that would
// cause it to require single quoting in YAML.
return 0 < preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
return 0 < preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` \p{Zs}]/xu', $value);
}
/**

View File

@ -635,6 +635,21 @@ YAML;
{
$this->assertSame('{ foo: ~ }', $this->dumper->dump(['foo' => null], 0, 0, Yaml::DUMP_NULL_AS_TILDE));
}
public function testDumpIdeographicSpaces()
{
$expected = <<<YAML
alone: ' '
within_string: 'a b'
regular_space: 'a b'
YAML;
$this->assertSame($expected, $this->dumper->dump([
'alone' => ' ',
'within_string' => 'a b',
'regular_space' => 'a b',
], 2));
}
}
class A

View File

@ -511,6 +511,10 @@ class InlineTest extends TestCase
['"0123\r"', "0123\r"],
['"0123\t"', "0123\t"],
['"0123\v"', "0123\v"],
// whitespaces
'ideographic space' => ["' '", ' '],
'ideographic space surrounded by characters' => ["'a b'", 'a b'],
];
}