merged branch unkind/bugfix-yaml-parse-exception (PR #8897)
This PR was merged into the 2.2 branch.
Discussion
----------
[Yaml] Fixed filename in the ParseException message
| Q | A
| ------------- | ---
| Bug fix? | sort of
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | —
| License | MIT
| Doc PR | —
Yaml component throws an exception with corrupt filename because of `json_encode`:
```
[Symfony\Component\Yaml\Exception\ParseException]
A YAML file cannot contain tabs as indentation in "\/var\/www\/app\/config.yml" at line 42 (near " foo: bar").
```
Commits
-------
da44651
[Yaml] Fixed filename in the ParseException message
This commit is contained in:
commit
1b789d2d16
|
@ -125,7 +125,7 @@ class ParseException extends RuntimeException
|
|||
}
|
||||
|
||||
if (null !== $this->parsedFile) {
|
||||
$this->message .= sprintf(' in %s', json_encode($this->parsedFile));
|
||||
$this->message .= sprintf(' in "%s"', $this->parsedFile);
|
||||
}
|
||||
|
||||
if ($this->parsedLine >= 0) {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Yaml\Tests;
|
||||
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ParseExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetMessage()
|
||||
{
|
||||
$exception = new ParseException(
|
||||
'Error message', 42, 'foo: bar', '/var/www/app/config.yml'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue