Skip to content

Commit 9919460

Browse files
committed
fix lexing inline sequences/mappings with trailing whitespaces
1 parent 8cac71f commit 9919460

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ private function parseValue(string $value, int $flags, string $context)
741741

742742
try {
743743
if ('' !== $value && '{' === $value[0]) {
744-
$cursor = \strlen($this->currentLine) - \strlen($value);
744+
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
745745

746746
return Inline::parse($this->lexInlineMapping($cursor), $flags, $this->refs);
747747
} elseif ('' !== $value && '[' === $value[0]) {
748-
$cursor = \strlen($this->currentLine) - \strlen($value);
748+
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
749749

750750
return Inline::parse($this->lexInlineSequence($cursor), $flags, $this->refs);
751751
}

Tests/ParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ public function testMultipleWhitespaceAtEndOfLine()
26832683
$this->parser->parse($yaml)
26842684
);
26852685

2686-
$yaml = "\nfoo:\n bar: {}\n";
2686+
$yaml = "\nfoo:\n bar: {} \n";
26872687
$this->assertSame(
26882688
[
26892689
'foo' => [

0 commit comments

Comments
 (0)