diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index d2d39b644e07..3212aeca5896 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -644,7 +644,7 @@ private static function parseTag($value, &$i, $flags) return; } - $tagLength = strcspn($value, " \t\n", $i + 1); + $tagLength = strcspn($value, " \t\n[]{},", $i + 1); $tag = substr($value, $i + 1, $tagLength); $nextOffset = $i + $tagLength + 1; diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index b1a4c1ccb5cd..784a26918237 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Inline; +use Symfony\Component\Yaml\Tag\TaggedValue; use Symfony\Component\Yaml\Yaml; class InlineTest extends TestCase @@ -695,4 +696,40 @@ public function getNotPhpCompatibleMappingKeyData() 'float' => array('{0.25: "foo"}', array('0.25' => 'foo')), ); } + + public function testTagWithoutValueInSequence() + { + $value = Inline::parse('[!foo]', Yaml::PARSE_CUSTOM_TAGS); + + $this->assertInstanceOf(TaggedValue::class, $value[0]); + $this->assertSame('foo', $value[0]->getTag()); + $this->assertSame('', $value[0]->getValue()); + } + + public function testTagWithEmptyValueInSequence() + { + $value = Inline::parse('[!foo ""]', Yaml::PARSE_CUSTOM_TAGS); + + $this->assertInstanceOf(TaggedValue::class, $value[0]); + $this->assertSame('foo', $value[0]->getTag()); + $this->assertSame('', $value[0]->getValue()); + } + + public function testTagWithoutValueInMapping() + { + $value = Inline::parse('{foo: !bar}', Yaml::PARSE_CUSTOM_TAGS); + + $this->assertInstanceOf(TaggedValue::class, $value['foo']); + $this->assertSame('bar', $value['foo']->getTag()); + $this->assertSame('', $value['foo']->getValue()); + } + + public function testTagWithEmptyValueInMapping() + { + $value = Inline::parse('{foo: !bar ""}', Yaml::PARSE_CUSTOM_TAGS); + + $this->assertInstanceOf(TaggedValue::class, $value['foo']); + $this->assertSame('bar', $value['foo']->getTag()); + $this->assertSame('', $value['foo']->getValue()); + } }