Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d67e1dd

Browse files
committed
[Yaml] parse inlined tags without values
1 parent 57e31c2 commit d67e1dd

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ private static function parseTag($value, &$i, $flags)
644644
return;
645645
}
646646

647-
$tagLength = strcspn($value, " \t\n", $i + 1);
647+
$tagLength = strcspn($value, " \t\n[]{},", $i + 1);
648648
$tag = substr($value, $i + 1, $tagLength);
649649

650650
$nextOffset = $i + $tagLength + 1;

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Yaml\Exception\ParseException;
1616
use Symfony\Component\Yaml\Inline;
17+
use Symfony\Component\Yaml\Tag\TaggedValue;
1718
use Symfony\Component\Yaml\Yaml;
1819

1920
class InlineTest extends TestCase
@@ -695,4 +696,40 @@ public function getNotPhpCompatibleMappingKeyData()
695696
'float' => array('{0.25: "foo"}', array('0.25' => 'foo')),
696697
);
697698
}
699+
700+
public function testTagWithoutValueInSequence()
701+
{
702+
$value = Inline::parse('[!foo]', Yaml::PARSE_CUSTOM_TAGS);
703+
704+
$this->assertInstanceOf(TaggedValue::class, $value[0]);
705+
$this->assertSame('foo', $value[0]->getTag());
706+
$this->assertSame('', $value[0]->getValue());
707+
}
708+
709+
public function testTagWithEmptyValueInSequence()
710+
{
711+
$value = Inline::parse('[!foo ""]', Yaml::PARSE_CUSTOM_TAGS);
712+
713+
$this->assertInstanceOf(TaggedValue::class, $value[0]);
714+
$this->assertSame('foo', $value[0]->getTag());
715+
$this->assertSame('', $value[0]->getValue());
716+
}
717+
718+
public function testTagWithoutValueInMapping()
719+
{
720+
$value = Inline::parse('{foo: !bar}', Yaml::PARSE_CUSTOM_TAGS);
721+
722+
$this->assertInstanceOf(TaggedValue::class, $value['foo']);
723+
$this->assertSame('bar', $value['foo']->getTag());
724+
$this->assertSame('', $value['foo']->getValue());
725+
}
726+
727+
public function testTagWithEmptyValueInMapping()
728+
{
729+
$value = Inline::parse('{foo: !bar ""}', Yaml::PARSE_CUSTOM_TAGS);
730+
731+
$this->assertInstanceOf(TaggedValue::class, $value['foo']);
732+
$this->assertSame('bar', $value['foo']->getTag());
733+
$this->assertSame('', $value['foo']->getValue());
734+
}
698735
}

0 commit comments

Comments
 (0)