Skip to content

Commit 4253854

Browse files
committed
bug symfony#13334 [Yaml] Fixed symfony#10597: Improved Yaml directive parsing (VictoriaQ)
This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes symfony#13334). Discussion ---------- [Yaml] Fixed symfony#10597: Improved Yaml directive parsing | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#10597 | License | MIT | Doc PR | N/A There was a problem with the regular expression used to process the YAML directive. The modifier `s` made the regex too greedy, replacing everything but the last line of the YAML. Existing tests using the YAML directive contained only one line, that's why they were passing. Commits ------- 95d8ce3 [Yaml] Fixed symfony#10597: Improved Yaml directive parsing
2 parents 1b39930 + 95d8ce3 commit 4253854

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ private function cleanup($value)
586586

587587
// strip YAML header
588588
$count = 0;
589-
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
589+
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value, -1, $count);
590590
$this->offset += $count;
591591

592592
// remove leading comments

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,17 @@ public function testReferenceResolvingInInlineStrings()
650650
EOF
651651
));
652652
}
653+
654+
public function testYamlDirective()
655+
{
656+
$yaml = <<<EOF
657+
%YAML 1.2
658+
---
659+
foo: 1
660+
bar: 2
661+
EOF;
662+
$this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml));
663+
}
653664
}
654665

655666
class B

0 commit comments

Comments
 (0)