merged branch jfsimon/issue-8145 (PR #8472)
This PR was merged into the 2.2 branch.
Discussion
----------
[Yaml] removed wrong comment removal inside a string block
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #8145
| License | MIT
| Doc PR | none
Commits
-------
9c5f8c6
[Yaml] removed wrong comment removal inside a string block
This commit is contained in:
commit
81a49c638a
|
@ -304,14 +304,16 @@ class Parser
|
||||||
|
|
||||||
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
|
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
|
||||||
|
|
||||||
while ($this->moveToNextLine()) {
|
// We are in string block (ie. after a line ending with "|")
|
||||||
|
$removeComments = !preg_match('~(.*)\|[\s]*$~', $this->currentLine);
|
||||||
|
|
||||||
|
while ($this->moveToNextLine()) {
|
||||||
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine)) {
|
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine)) {
|
||||||
$this->moveToPreviousLine();
|
$this->moveToPreviousLine();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isCurrentLineEmpty()) {
|
if ($removeComments && $this->isCurrentLineEmpty() || $this->isCurrentLineBlank()) {
|
||||||
if ($this->isCurrentLineBlank()) {
|
if ($this->isCurrentLineBlank()) {
|
||||||
$data[] = substr($this->currentLine, $newIndent);
|
$data[] = substr($this->currentLine, $newIndent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -522,6 +522,63 @@ EOF;
|
||||||
|
|
||||||
$this->assertEquals(array('hash' => null), Yaml::parse($input));
|
$this->assertEquals(array('hash' => null), Yaml::parse($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testStringBlockWithComments()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array('content' => <<<EOT
|
||||||
|
# comment 1
|
||||||
|
header
|
||||||
|
|
||||||
|
# comment 2
|
||||||
|
<body>
|
||||||
|
<h1>title</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
footer # comment3
|
||||||
|
EOT
|
||||||
|
), Yaml::parse(<<<EOF
|
||||||
|
content: |
|
||||||
|
# comment 1
|
||||||
|
header
|
||||||
|
|
||||||
|
# comment 2
|
||||||
|
<body>
|
||||||
|
<h1>title</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
footer # comment3
|
||||||
|
EOF
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedStringBlockWithComments()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array(array('content' => <<<EOT
|
||||||
|
# comment 1
|
||||||
|
header
|
||||||
|
|
||||||
|
# comment 2
|
||||||
|
<body>
|
||||||
|
<h1>title</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
footer # comment3
|
||||||
|
EOT
|
||||||
|
)), Yaml::parse(<<<EOF
|
||||||
|
-
|
||||||
|
content: |
|
||||||
|
# comment 1
|
||||||
|
header
|
||||||
|
|
||||||
|
# comment 2
|
||||||
|
<body>
|
||||||
|
<h1>title</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
footer # comment3
|
||||||
|
EOF
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class B
|
class B
|
||||||
|
|
Reference in New Issue