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

Skip to content

[Yaml] parse inlined tags without values #23757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}