bug #33818 [Yaml] Throw exception for tagged invalid inline elements (gharlan)
This PR was merged into the 3.4 branch.
Discussion
----------
[Yaml] Throw exception for tagged invalid inline elements
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | n/a
| License | MIT
| Doc PR | n/a
At the moment the result for `!foo 'don't do somthin' like that'` is a `TaggedValue` with value "don".
Commits
-------
bed479c561
[Yaml] Throw exception for tagged invalid inline elements
This commit is contained in:
commit
52f8fc839c
@ -126,15 +126,15 @@ class Inline
|
|||||||
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
|
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $tag) {
|
|
||||||
return new TaggedValue($tag, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// some comments are allowed at the end
|
// some comments are allowed at the end
|
||||||
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
|
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
|
||||||
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null !== $tag) {
|
||||||
|
return new TaggedValue($tag, $result);
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
} finally {
|
} finally {
|
||||||
if (isset($mbEncoding)) {
|
if (isset($mbEncoding)) {
|
||||||
|
@ -201,6 +201,12 @@ class InlineTest extends TestCase
|
|||||||
Inline::parse('{ foo: bar } bar');
|
Inline::parse('{ foo: bar } bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParseInvalidTaggedSequenceShouldThrowException()
|
||||||
|
{
|
||||||
|
$this->expectException('Symfony\Component\Yaml\Exception\ParseException');
|
||||||
|
Inline::parse('!foo { bar: baz } qux', Yaml::PARSE_CUSTOM_TAGS);
|
||||||
|
}
|
||||||
|
|
||||||
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
|
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
|
||||||
{
|
{
|
||||||
$value = "'don''t do somthin'' like that'";
|
$value = "'don''t do somthin'' like that'";
|
||||||
|
Reference in New Issue
Block a user