Skip to content

Commit cc94e33

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: Fix nullable parameter doc don't try to replace references in quoted strings
2 parents 4500fe6 + 878d63b commit cc94e33

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
@@ -387,7 +387,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
387387
}
388388
}
389389

390-
if (\is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
390+
if (!$isQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
391391
$references[$matches['ref']] = $matches['value'];
392392
$value = $matches['value'];
393393
}
@@ -521,6 +521,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
521521
}
522522
break;
523523
default:
524+
$isValueQuoted = \in_array($mapping[$i], ['"', "'"]);
524525
$value = self::parseScalar($mapping, $flags, [',', '}', "\n"], $i, null === $tag, $references);
525526
// Spec: Keys MUST be unique; first one wins.
526527
// Parser cannot abort this mapping earlier, since lines
@@ -529,7 +530,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
529530
if ('<<' === $key) {
530531
$output += $value;
531532
} elseif ($allowOverwrite || !isset($output[$key])) {
532-
if (\is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
533+
if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
533534
$references[$matches['ref']] = $matches['value'];
534535
$value = $matches['value'];
535536
}

Tests/InlineTest.php

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

0 commit comments

Comments
 (0)