quote all dumped unicode spaces

This commit is contained in:
Christian Flothmann 2021-01-09 13:36:14 +01:00
parent 3ee310f20a
commit 0028efe8f8
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'],
];
}