Skip to content

Commit

Permalink
bug #23171 [Yaml] Fix linting yaml with constants as keys (chalasr)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.3 branch.

Discussion
----------

[Yaml] Fix linting yaml with constants as keys

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23167
| License       | MIT
| Doc PR        | n/a

<!--
- Bug fixes must be submitted against the lowest branch where they apply
  (lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the 3.4,
  legacy code removals go to the master branch.
- Please fill in this template according to the PR you're about to submit.
- Replace this comment by a description of what your PR is solving.
-->

Commits
-------

55a8d35 [Yaml] Fix linting yaml with constants as keys
  • Loading branch information
fabpot committed Jun 14, 2017
2 parents 9649b9e + 55a8d35 commit 748a999
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Symfony/Component/Yaml/Command/LintCommand.php
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;

/**
* Validates YAML files syntax and outputs encountered errors.
Expand Down Expand Up @@ -111,7 +112,7 @@ private function validate($content, $file = null)
});

try {
$this->getParser()->parse($content);
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
} finally {
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Yaml/Tests/Command/LintCommandTest.php
Expand Up @@ -51,6 +51,15 @@ public function testLintIncorrectFile()
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
}

public function testConstantAsKey()
{
$yaml = <<<YAML
!php/const:Symfony\Component\Yaml\Tests\Command\Foo::TEST: bar
YAML;
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
}

/**
* @expectedException \RuntimeException
*/
Expand Down Expand Up @@ -105,3 +114,8 @@ protected function tearDown()
rmdir(sys_get_temp_dir().'/framework-yml-lint-test');
}
}

class Foo
{
const TEST = 'foo';
}

0 comments on commit 748a999

Please sign in to comment.