8000 parse newlines in quoted multiline strings · symfony/symfony@b23b957 · GitHub
[go: up one dir, main page]

Skip to content

Commit b23b957

Browse files
committed
parse newlines in quoted multiline strings
1 parent 5b997f1 commit b23b957

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ private function parseValue($value, $flags, $context)
700700
return Inline::parse($value, $flags, $this->refs);
701701
}
702702

703+
$lines = array();
704+
703705
while ($this->moveToNextLine()) {
704706
// unquoted strings end before the first unindented line
705707
if (null === $quotation && 0 === $this->getCurrentLineIndentation()) {
@@ -708,14 +710,27 @@ private function parseValue($value, $flags, $context)
708710
break;
709711
}
710712

711-
$value .= ' '.trim($this->currentLine);
713+
$lines[] = trim($this->currentLine);
712714

713715
// quoted string values end with a line that is terminated with the quotation character
714716
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
715717
break;
716718
}
717719
}
718720

721+
for ($i = 0, $linesCount = count($lines), $previousLineBlank = false; $i < $linesCount; ++$i) {
722+
if ('' === $lines[$i]) {
723+
$value .= "\n";
724+
$previousLineBlank = true;
725+
} elseif ($previousLineBlank) {
726+
$value .= $lines[$i];
727+
$previousLineBlank = false;
728+
} else {
729+
$value .= ' '.$lines[$i];
730+
$previousLineBlank = false;
731+
}
732+
}
733+
719734
Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
720735
$parsedValue = Inline::parse($value, $flags, $this->refs);
721736

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,20 @@ public function testCommentCharactersInMultiLineQuotedStrings()
15721572
$this->assertSame($expected, $this->parser->parse($yaml));
15731573
}
15741574

1575+
public function testBlankLinesInQuotedMultiLineString()
1576+
{
1577+
$yaml = <<<YAML
1578+
foobar: 'foo
1579+
1580+
bar'
1581+
YAML;
1582+
$expected = array(
1583+
'foobar' => "foo\nbar",
1584+
);
1585+
1586+
$this->assertSame($expected, $this->parser->parse($yaml));
1587+
}
1588+
15751589
public function testParseMultiLineUnquotedString()
15761590
{
15771591
$yaml = <<<EOT

0 commit comments

Comments
 (0)
0