minor #20388 [Yaml] Clean some messages + add test case (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Yaml] Clean some messages + add test case

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

Related to #20335 on 3.2.

Commits
-------

7520f7b [Yaml] Clean some messages + add test case
This commit is contained in:
Fabien Potencier 2016-11-02 14:11:25 -07:00
commit df130a35e4
2 changed files with 13 additions and 4 deletions

View File

@ -249,7 +249,7 @@ class Inline
$output = $match[1]; $output = $match[1];
$i += strlen($output); $i += strlen($output);
} else { } else {
throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar)); throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar));
} }
if ($evaluate) { if ($evaluate) {
@ -273,7 +273,7 @@ class Inline
private static function parseQuotedScalar($scalar, &$i) private static function parseQuotedScalar($scalar, &$i)
{ {
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) { if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
throw new ParseException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i))); throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i)));
} }
$output = substr($match[0], 1, strlen($match[0]) - 2); $output = substr($match[0], 1, strlen($match[0]) - 2);
@ -346,7 +346,7 @@ class Inline
++$i; ++$i;
} }
throw new ParseException(sprintf('Malformed inline YAML string %s', $sequence)); throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence));
} }
/** /**
@ -434,7 +434,7 @@ class Inline
} }
} }
throw new ParseException(sprintf('Malformed inline YAML string %s', $mapping)); throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping));
} }
/** /**

View File

@ -401,4 +401,13 @@ class InlineTest extends \PHPUnit_Framework_TestCase
array('{ foo: { bar: { 1: 2, baz: 3 } } }', array('foo' => array('bar' => array(1 => 2, 'baz' => 3)))), array('{ foo: { bar: { 1: 2, baz: 3 } } }', array('foo' => array('bar' => array(1 => 2, 'baz' => 3)))),
); );
} }
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported}.
*/
public function testNotSupportedMissingValue()
{
Inline::parse('{this, is not, supported}');
}
} }