Skip to content

Commit 8e9fcae

Browse files
committed
quote all dumped unicode spaces
1 parent 3fda4df commit 8e9fcae

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Escaper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function requiresSingleQuoting(string $value): bool
8686

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

9292
/**

Tests/DumperTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,21 @@ public function testDumpNullAsTilde()
635635
{
636636
$this->assertSame('{ foo: ~ }', $this->dumper->dump(['foo' => null], 0, 0, Yaml::DUMP_NULL_AS_TILDE));
637637
}
638+
639+
public function testDumpIdeographicSpaces()
640+
{
641+
$expected = <<<YAML
642+
alone: ' '
643+
within_string: 'a b'
644+
regular_space: 'a b'
645+
646+
YAML;
647+
$this->assertSame($expected, $this->dumper->dump([
648+
'alone' => ' ',
649+
'within_string' => 'a b',
650+
'regular_space' => 'a b',
651+
], 2));
652+
}
638653
}
639654

640655
class A

Tests/InlineTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ public function getTestsForDump()
511511
['"0123\r"', "0123\r"],
512512
['"0123\t"', "0123\t"],
513513
['"0123\v"', "0123\v"],
514+
515+
// whitespaces
516+
'ideographic space' => ["' '", ' '],
517+
'ideographic space surrounded by characters' => ["'a b'", 'a b'],
514518
];
515519
}
516520

0 commit comments

Comments
 (0)