Skip to content

Commit dd3f776

Browse files
committed
a colon followed by spaces exclusively separates mapping keys and values
1 parent 22640fb commit dd3f776

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private function doParse(string $value, int $flags)
200200
array_pop($this->refsBeingParsed);
201201
}
202202
} elseif (
203-
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
203+
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:( ++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
204204
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
205205
) {
206206
if ($context && 'sequence' == $context) {

Tests/InlineTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,4 +877,21 @@ public function quotedExclamationMarkProvider()
877877
[['!'], '! ["!"]'],
878878
];
879879
}
880+
881+
/**
882+
* @dataProvider ideographicSpaceProvider
883+
*/
884+
public function testParseIdeographicSpace(string $yaml, string $expected)
885+
{
886+
$this->assertSame($expected, Inline::parse($yaml));
887+
}
888+
889+
public function ideographicSpaceProvider(): array
890+
{
891+
return [
892+
["\u{3000}", ' '],
893+
["'\u{3000}'", ' '],
894+
["'a b'", 'a b'],
895+
];
896+
}
880897
}

Tests/ParserTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,22 @@ public function testParsingMultipleDocuments()
27332733
// (before, there was no \n after row2)
27342734
$this->assertSame(['a' => ['b' => "row\nrow2\n"], 'c' => 'd'], $this->parser->parse($longDocument));
27352735
}
2736+
2737+
public function testParseIdeographicSpaces()
2738+
{
2739+
$expected = <<<YAML
2740+
unquoted: \u{3000}
2741+
quoted: '\u{3000}'
2742+
within_string: 'a b'
2743+
regular_space: 'a b'
2744+
YAML;
2745+
$this->assertSame([
2746+
'unquoted' => ' ',
2747+
'quoted' => ' ',
2748+
'within_string' => 'a b',
2749+
'regular_space' => 'a b',
2750+
], $this->parser->parse($expected));
2751+
}
27362752
}
27372753

27382754
class B

0 commit comments

Comments
 (0)