Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff8d4ba

Browse files
committed
Fixed incorrect behavior for mappings inside multiline string
1 parent 007ae9a commit ff8d4ba

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,16 @@ private function doParse(string $value, int $flags)
376376
$previousLineWasTerminatedWithBackslash = false;
377377
$value = '';
378378

379-
foreach ($this->lines as $line) {
379+
foreach ($this->lines as $multiLineIncrement => $line) {
380380
// If the indentation is not consistent at offset 0, it is to be considered as a ParseError
381381
if (0 === $this->offset && !$deprecatedUsage && isset($line[0]) && ' ' === $line[0]) {
382382
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
383383
}
384384

385-
if ($this->offset >= 1 && strpos($this->currentLine, ':') && $this->isNextLineIndented()) {
386-
@trigger_error('Support for indented blocks after definition is deprecated since version 4.1. Use same level of indentation to fix this issue.', E_USER_DEPRECATED);
385+
$nextLine = $this->lines[$multiLineIncrement + 1] ?? false;
386+
387+
if ($this->offset >= 1 && $this->isNextLineIndented() && ($nextLine && strpos($nextLine, ': '))) {
388+
@trigger_error('Support for mapping keys in multiline blocks is deprecated since version 4.1.', E_USER_DEPRECATED);
387389
}
388390

389391
if ('' === trim($line)) {

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ public function testObjectsSupportDisabledWithExceptions()
527527

528528
/**
529529
* @group legacy
530-
* @expectedDeprecation Support for indented blocks after definition is deprecated since version 4.1. Use same level of indentation to fix this issue.
530+
* @expectedDeprecation Support for mapping keys in multiline blocks is deprecated since version 4.1.
531531
*/
532-
public function testMappingKeyWithAdditionalStringThrowsException()
532+
public function testMappingKeyInMultiLineStringTriggersDeprecationNotice()
533533
{
534534
$yaml = <<<'EOF'
535535
data:
@@ -749,9 +749,10 @@ public function testMultiLineStringLastResortParsing()
749749
You can have things that don't look like strings here
750750
true
751751
yes you can
752+
with a: colon
752753
EOT;
753754
$expected = array(
754-
'test' => 'You can have things that don\'t look like strings here true yes you can',
755+
'test' => 'You can have things that don\'t look like strings here true yes you can with a: colon',
755756
);
756757

757758
$this->assertSame($expected, $this->parser->parse($yaml));

0 commit comments

Comments
 (0)