Skip to content

Commit 9744e59

Browse files
committed
Added deprecation notice when mapping keys are found in multi-line blocks
1 parent 4c7b2f8 commit 9744e59

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.
8+
49
4.2.0
510
-----
611

Parser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ private function doParse(string $value, int $flags)
390390
if (0 === $this->offset && !$deprecatedUsage && isset($line[0]) && ' ' === $line[0]) {
391391
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
392392
}
393+
394+
if (false !== strpos($line, ': ')) {
395+
@trigger_error('Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0.', E_USER_DEPRECATED);
396+
}
397+
393398
if ('' === trim($line)) {
394399
$value .= "\n";
395400
} elseif (!$previousLineWasNewline && !$previousLineWasTerminatedWithBackslash) {

Tests/ParserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,20 @@ public function testObjectsSupportDisabledWithExceptions()
525525
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
526526
}
527527

528+
/**
529+
* @group legacy
530+
* @expectedDeprecation Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0.
531+
*/
532+
public function testMappingKeyInMultiLineStringTriggersDeprecationNotice()
533+
{
534+
$yaml = <<<'EOF'
535+
data:
536+
dbal:wrong
537+
default_connection: monolith
538+
EOF;
539+
$this->parser->parse($yaml);
540+
}
541+
528542
public function testCanParseContentWithTrailingSpaces()
529543
{
530544
$yaml = "items: \n foo: bar";

0 commit comments

Comments
 (0)