bug #13375 [YAML] Fix one-liners to work with multiple new lines (Alex Pott)
This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #13375).
Discussion
----------
[YAML] Fix one-liners to work with multiple new lines
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | none
| License | MIT
| Doc PR | n/a
Commits
-------
4d22bf7
[YAML] Fix one-liners to work with multiple new lines
This commit is contained in:
commit
33bf087a9b
@ -51,13 +51,13 @@ class Parser
|
||||
*/
|
||||
public function parse($value, $exceptionOnInvalidType = false, $objectSupport = false)
|
||||
{
|
||||
$this->currentLineNb = -1;
|
||||
$this->currentLine = '';
|
||||
$this->lines = explode("\n", $this->cleanup($value));
|
||||
|
||||
if (!preg_match('//u', $value)) {
|
||||
throw new ParseException('The YAML value does not appear to be valid UTF-8.');
|
||||
}
|
||||
$this->currentLineNb = -1;
|
||||
$this->currentLine = '';
|
||||
$value = $this->cleanup($value);
|
||||
$this->lines = explode("\n", $value);
|
||||
|
||||
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
|
||||
$mbEncoding = mb_internal_encoding();
|
||||
@ -197,9 +197,8 @@ class Parser
|
||||
throw new ParseException('Multiple documents are not supported.');
|
||||
}
|
||||
|
||||
// 1-liner optionally followed by newline
|
||||
$lineCount = count($this->lines);
|
||||
if (1 === $lineCount || (2 === $lineCount && empty($this->lines[1]))) {
|
||||
// 1-liner optionally followed by newline(s)
|
||||
if ($this->lines[0] === trim($value)) {
|
||||
try {
|
||||
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $this->refs);
|
||||
} catch (ParseException $e) {
|
||||
|
@ -135,6 +135,14 @@ EOF;
|
||||
);
|
||||
$tests['Literal block chomping strip with multiple trailing newlines'] = array($expected, $yaml);
|
||||
|
||||
$yaml = <<<'EOF'
|
||||
{}
|
||||
|
||||
|
||||
EOF;
|
||||
$expected = array();
|
||||
$tests['Literal block chomping strip with multiple trailing newlines after a 1-liner'] = array($expected, $yaml);
|
||||
|
||||
$yaml = <<<'EOF'
|
||||
foo: |-
|
||||
one
|
||||
|
Reference in New Issue
Block a user