8000 [Yaml] parse newlines in quoted multiline strings by xabbuh · Pull Request #25309 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Yaml] parse newlines in quoted multiline strings #25309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ private function parseValue($value, $flags, $context)
return Inline::parse($value, $flags, $this->refs);
}

$lines = array();

while ($this->moveToNextLine()) {
// unquoted strings end before the first unindented line
if (null === $quotation && 0 === $this->getCurrentLineIndentation()) {
Expand All @@ -708,14 +710,27 @@ private function parseValue($value, $flags, $context)
break;
}

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

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

for ($i = 0, $linesCount = count($lines), $previousLineBlank = false; $i < $linesCount; ++$i) {
if ('' === $lines[$i]) {
$value .= "\n";
$previousLineBlank = true;
} elseif ($previousLineBlank) {
$value .= $lines[$i];
$previousLineBlank = false;
} else {
$value .= ' '.$lines[$i];
$previousLineBlank = false;
}
}

Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
$parsedValue = Inline::parse($value, $flags, $this->refs);

Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,20 @@ public function testCommentCharactersInMultiLineQuotedStrings()
$this->assertSame($expected, $this->parser->parse($yaml));
}

public function testBlankLinesInQuotedMultiLineString()
{
$yaml = <<<YAML
foobar: 'foo

bar'
YAML;
$expected = array(
'foobar' => "foo\nbar",
);

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

public function testParseMultiLineUnquotedString()
{
$yaml = <<<EOT
Expand Down
0