[YAML] Fix one-liners to work with multiple new lines
This commit is contained in:
parent
b97e5437c7
commit
4d22bf7f72
@ -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