bug #39787 [Yaml] a colon followed by spaces exclusively separates mapping keys and values (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Yaml] a colon followed by spaces exclusively separates mapping keys and values

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix https://github.com/symfony/symfony/pull/39769#issuecomment-757540072
| License       | MIT
| Doc PR        |

Commits
-------

f72c6a5ad4 a colon followed by spaces exclusively separates mapping keys and values
This commit is contained in:
Nicolas Grekas 2021-01-12 12:26:39 +01:00
commit 7aad82480d
3 changed files with 34 additions and 1 deletions

View File

@ -200,7 +200,7 @@ class Parser
array_pop($this->refsBeingParsed);
}
} elseif (
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:( ++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
) {
if ($context && 'sequence' == $context) {

View File

@ -877,4 +877,21 @@ class InlineTest extends TestCase
[['!'], '! ["!"]'],
];
}
/**
* @dataProvider ideographicSpaceProvider
*/
public function testParseIdeographicSpace(string $yaml, string $expected)
{
$this->assertSame($expected, Inline::parse($yaml));
}
public function ideographicSpaceProvider(): array
{
return [
["\u{3000}", ' '],
["'\u{3000}'", ' '],
["'a b'", 'a b'],
];
}
}

View File

@ -2733,6 +2733,22 @@ YAML;
// (before, there was no \n after row2)
$this->assertSame(['a' => ['b' => "row\nrow2\n"], 'c' => 'd'], $this->parser->parse($longDocument));
}
public function testParseIdeographicSpaces()
{
$expected = <<<YAML
unquoted: \u{3000}
quoted: '\u{3000}'
within_string: 'a b'
regular_space: 'a b'
YAML;
$this->assertSame([
'unquoted' => ' ',
'quoted' => ' ',
'within_string' => 'a b',
'regular_space' => 'a b',
], $this->parser->parse($expected));
}
}
class B