bug #23757 [Yaml] parse inlined tags without values (xabbuh)
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
This commit is contained in:
commit
11f940c7f3
@ -644,7 +644,7 @@ class Inline
|
||||
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;
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Yaml\Tests;
|
||||
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 @@ class InlineTest extends TestCase
|
||||
'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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user