Skip to content

Commit

Permalink
bug #23757 [Yaml] parse inlined tags without values (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.0-dev branch.

Discussion
----------

[Yaml] parse inlined tags without values

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

3bb0a3f [Yaml] parse inlined tags without values
  • Loading branch information
xabbuh committed Aug 10, 2017
2 parents 8088661 + 3bb0a3f commit 11f940c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Inline.php
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
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());
}
}

0 comments on commit 11f940c

Please sign in to comment.