Skip to content

Commit 9e6346b

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: Fix nullable parameter doc don't try to replace references in quoted strings
2 parents f1dc583 + cc94e33 commit 9e6346b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Inline.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
389389
}
390390
}
391391

392-
if (\is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
392+
if (!$isQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
393393
$references[$matches['ref']] = $matches['value'];
394394
$value = $matches['value'];
395395
}
@@ -523,6 +523,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
523523
}
524524
break;
525525
default:
526+
$isValueQuoted = \in_array($mapping[$i], ['"', "'"]);
526527
$value = self::parseScalar($mapping, $flags, [',', '}', "\n"], $i, null === $tag, $references);
527528
// Spec: Keys MUST be unique; first one wins.
528529
// Parser cannot abort this mapping earlier, since lines
@@ -531,7 +532,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
531532
if ('<<' === $key) {
532533
$output += $value;
533534
} elseif ($allowOverwrite || !isset($output[$key])) {
534-
if (\is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
535+
if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
535536
$references[$matches['ref']] = $matches['value'];
536537
$value = $matches['value'];
537538
}

Tests/InlineTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,4 +945,22 @@ public function ideographicSpaceProvider(): array
945945
["'a b'", 'a b'],
946946
];
947947
}
948+
949+
public function testParseQuotedReferenceLikeStringsInMapping()
950+
{
951+
$yaml = <<<YAML
952+
{foo: '&foo', bar: "&bar"}
953+
YAML;
954+
955+
$this->assertSame(['foo' => '&foo', 'bar' => '&bar'], Inline::parse($yaml));
956+
}
957+
958+
public function testParseQuotedReferenceLikeStringsInSequence()
959+
{
960+
$yaml = <<<YAML
961+
['&foo', "&bar" ]
962+
YAML;
963+
964+
$this->assertSame(['&foo', '&bar'], Inline::parse($yaml));
965+
}
948966
}

0 commit comments

Comments
 (0)