bug #25309 [Yaml] parse newlines in quoted multiline strings (xabbuh)
This PR was merged into the 3.3 branch.
Discussion
----------
[Yaml] parse newlines in quoted multiline strings
| Q | A
| ------------- | ---
| Branch? | 3.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Commits
-------
b23b957ae9
parse newlines in quoted multiline strings
This commit is contained in:
commit
c08602cb80
@ -700,6 +700,8 @@ class Parser
|
|||||||
return Inline::parse($value, $flags, $this->refs);
|
return Inline::parse($value, $flags, $this->refs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lines = array();
|
||||||
|
|
||||||
while ($this->moveToNextLine()) {
|
while ($this->moveToNextLine()) {
|
||||||
// unquoted strings end before the first unindented line
|
// unquoted strings end before the first unindented line
|
||||||
if (null === $quotation && 0 === $this->getCurrentLineIndentation()) {
|
if (null === $quotation && 0 === $this->getCurrentLineIndentation()) {
|
||||||
@ -708,7 +710,7 @@ class Parser
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value .= ' '.trim($this->currentLine);
|
$lines[] = trim($this->currentLine);
|
||||||
|
|
||||||
// quoted string values end with a line that is terminated with the quotation character
|
// quoted string values end with a line that is terminated with the quotation character
|
||||||
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
|
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
|
||||||
@ -716,6 +718,19 @@ class Parser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
|
||||||
$parsedValue = Inline::parse($value, $flags, $this->refs);
|
$parsedValue = Inline::parse($value, $flags, $this->refs);
|
||||||
|
|
||||||
|
@ -1572,6 +1572,20 @@ YAML;
|
|||||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
$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()
|
public function testParseMultiLineUnquotedString()
|
||||||
{
|
{
|
||||||
$yaml = <<<EOT
|
$yaml = <<<EOT
|
||||||
|
Reference in New Issue
Block a user