Skip to content

Commit

Permalink
merged branch unkind/bugfix-yaml-parse-exception (PR #8897)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Sep 19, 2013
2 parents 6a36fb6 + da44651 commit 1b789d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Exception/ParseException.php
Expand Up @@ -125,7 +125,7 @@ private function updateRepr()
}

if (null !== $this->parsedFile) {
$this->message .= sprintf(' in %s', json_encode($this->parsedFile));
$this->message .= sprintf(' in "%s"', $this->parsedFile);
}

if ($this->parsedLine >= 0) {
Expand Down
30 changes: 30 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParseExceptionTest.php
@@ -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()
);
}
}

0 comments on commit 1b789d2

Please sign in to comment.