merged branch ezzatron/yaml-folded-leading-newlines (PR #7997)
This PR was merged into the 2.1 branch.
Discussion
----------
Fixed parsing of leading blank lines in folded scalars.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #7989
| License | MIT
| Doc PR | n/a
Fixed the issue raised in #7989. The cause was in the way the parser determined the indentation level of block scalars. When the indentation is not manually specified, the parser now determines the indentation from the first *non-empty* line as per section [8.1.1.1.](http://www.yaml.org/spec/1.2/spec.html#id2793979) of the spec.
Commits
-------
a5441b2
Fixed parsing of leading blank lines in folded scalars. Closes #7989.
This commit is contained in:
commit
181d0c6ed0
@ -419,6 +419,18 @@ class Parser
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||||
|
$text = '';
|
||||||
|
|
||||||
|
// leading blank lines are consumed before determining indentation
|
||||||
|
while ($notEOF && $isCurrentLineBlank) {
|
||||||
|
// newline only if not EOF
|
||||||
|
if ($notEOF = $this->moveToNextLine()) {
|
||||||
|
$text .= "\n";
|
||||||
|
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// determine indentation if not specified
|
// determine indentation if not specified
|
||||||
if (0 === $indentation) {
|
if (0 === $indentation) {
|
||||||
if (preg_match('/^ +/', $this->currentLine, $matches)) {
|
if (preg_match('/^ +/', $this->currentLine, $matches)) {
|
||||||
@ -426,11 +438,9 @@ class Parser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = '';
|
|
||||||
if ($indentation > 0) {
|
if ($indentation > 0) {
|
||||||
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);
|
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);
|
||||||
|
|
||||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
|
||||||
while (
|
while (
|
||||||
$notEOF && (
|
$notEOF && (
|
||||||
$isCurrentLineBlank ||
|
$isCurrentLineBlank ||
|
||||||
|
@ -396,6 +396,27 @@ EOF;
|
|||||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression test for issue #7989.
|
||||||
|
*
|
||||||
|
* @see https://github.com/symfony/symfony/issues/7989
|
||||||
|
*/
|
||||||
|
public function testBlockLiteralWithLeadingNewlines()
|
||||||
|
{
|
||||||
|
$yaml = <<<'EOF'
|
||||||
|
foo: |-
|
||||||
|
|
||||||
|
|
||||||
|
bar
|
||||||
|
|
||||||
|
EOF;
|
||||||
|
$expected = array(
|
||||||
|
'foo' => "\n\nbar"
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||||
|
}
|
||||||
|
|
||||||
public function testObjectSupportEnabled()
|
public function testObjectSupportEnabled()
|
||||||
{
|
{
|
||||||
$input = <<<EOF
|
$input = <<<EOF
|
||||||
|
Reference in New Issue
Block a user