Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f1cb4b5

Browse filesBrowse files
bug #32767 [Yaml] fix comment in multi line value (soufianZantar)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] fix comment in multi line value | Q | A | ------------- | --- | Branch? | 4.3 and lower <!-- see below --> | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #32667 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained 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 branch 4.4. - Legacy code removals go to the master branch. --> Comments after blank lines are read as value in yaml. ``` `$yaml = <<<YAML parameters: abc # Comment YAML; var_dump(Symfony\Component\Yaml\Yaml::parse($yaml));` ``` **Result before fix:** ``` array(1) { ["parameters"]=> string(13) "abc # Comment" } ``` **Result after fix:** ``` array(1) { ["parameters"]=> string(3) "abc" } ``` Commits ------- dd945e3 fix(yml): fix comment in milti line value
2 parents 1143b02 + dd945e3 commit f1cb4b5
Copy full SHA for f1cb4b5

File tree

2 files changed

+15
-0
lines changed
Filter options

2 files changed

+15
-0
lines changed

‎src/Symfony/Component/Yaml/Parser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Parser.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ private function doParse($value, $flags)
436436
$value = '';
437437

438438
foreach ($this->lines as $line) {
439+
if ('' !== ltrim($line) && '#' === ltrim($line)[0]) {
440+
continue;
441+
}
439442
// If the indentation is not consistent at offset 0, it is to be considered as a ParseError
440443
if (0 === $this->offset && !$deprecatedUsage && isset($line[0]) && ' ' === $line[0]) {
441444
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);

‎src/Symfony/Component/Yaml/Tests/ParserTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/ParserTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,18 @@ public function indentedMappingData()
22922292

22932293
return $tests;
22942294
}
2295+
2296+
public function testMultiLineComment()
2297+
{
2298+
$yaml = <<<YAML
2299+
parameters:
2300+
abc
2301+
2302+
# Comment
2303+
YAML;
2304+
2305+
$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));
2306+
}
22952307
}
22962308

22972309
class B

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.