Skip to content

Commit 640e162

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Fix nullable parameter doc don't try to replace references in quoted strings
2 parents 6e88d8c + 9e6346b commit 640e162

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
@@ -365,7 +365,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
365365
}
366366
}
367367

368-
if (\is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
368+
if (!$isQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
369369
$references[$matches['ref']] = $matches['value'];
370370
$value = $matches['value'];
371371
}
@@ -497,6 +497,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
497497
}
498498
break;
499499
default:
500+
$isValueQuoted = \in_array($mapping[$i], ['"', "'"]);
500501
$value = self::parseScalar($mapping, $flags, [',', '}', "\n"], $i, null === $tag, $references);
501502
// Spec: Keys MUST be unique; first one wins.
502503
// Parser cannot abort this mapping earlier, since lines
@@ -505,7 +506,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
505506
if ('<<' === $key) {
506507
$output += $value;
507508
} elseif ($allowOverwrite || !isset($output[$key])) {
508-
if (\is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
509+
if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
509510
$references[$matches['ref']] = $matches['value'];
510511
$value = $matches['value'];
511512
}

Tests/InlineTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,4 +923,22 @@ public function ideographicSpaceProvider(): array
923923
["'a b'", 'a b'],
924924
];
925925
}
926+
927+
public function testParseQuotedReferenceLikeStringsInMapping()
928+
{
929+
$yaml = <<<YAML
930+
{foo: '&foo', bar: "&bar"}
931+
YAML;
932+
933+
$this->assertSame(['foo' => '&foo', 'bar' => '&bar'], Inline::parse($yaml));
934+
}
935+
936+
public function testParseQuotedReferenceLikeStringsInSequence()
937+
{
938+
$yaml = <<<YAML
939+
['&foo', "&bar" ]
940+
YAML;
941+
942+
$this->assertSame(['&foo', '&bar'], Inline::parse($yaml));
943+
}
926944
}

0 commit comments

Comments
 (0)