bug #13334 [Yaml] Fixed #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 #13334).

Discussion
----------

[Yaml] Fixed #10597: Improved Yaml directive parsing

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #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 #10597: Improved Yaml directive parsing
This commit is contained in:
Fabien Potencier 2015-01-09 15:23:47 +01:00
commit 425385400d
2 changed files with 12 additions and 1 deletions

View File

@ -586,7 +586,7 @@ class Parser
// strip YAML header
$count = 0;
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value, -1, $count);
$this->offset += $count;
// remove leading comments

View File

@ -650,6 +650,17 @@ map_in_map: { foo: { bar: *var } }
EOF
));
}
public function testYamlDirective()
{
$yaml = <<<EOF
%YAML 1.2
---
foo: 1
bar: 2
EOF;
$this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml));
}
}
class B