Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 094ca41

Browse files
committed
Merge branch '2.8'
* 2.8: [Yaml] Add regression test for comments indents Fix the DomCrawler tests Revert "bug #15860 [Yaml] Fix improper comments removal (ogizanagi)"
2 parents 8fdb412 + f4a2752 commit 094ca41

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,6 @@ public function addNodes(array $nodes)
313313
*/
314314
public function addNode(\DOMNode $node)
315315
{
316-
if (null !== $this->document && $this->document !== $node->ownerDocument) {
317-
@trigger_error('Attaching DOM nodes from multiple documents in a Crawler is deprecated as of 2.8 and will be forbidden in 3.0.', E_USER_DEPRECATED);
318-
}
319-
320-
if (null === $this->document) {
321-
$this->document = $node->ownerDocument;
322-
}
323-
324316
if ($node instanceof \DOMDocument) {
325317
$node = $node->documentElement;
326318
}
@@ -329,6 +321,14 @@ public function addNode(\DOMNode $node)
329321
throw new \InvalidArgumentException(sprintf('Nodes set in a Crawler must be DOMElement or DOMDocument instances, "%s" given.', get_class($node)));
330322
}
331323

324+
if (null !== $this->document && $this->document !== $node->ownerDocument) {
325+
@trigger_error('Attaching DOM nodes from multiple documents in a Crawler is deprecated as of 2.8 and will be forbidden in 3.0.', E_USER_DEPRECATED);
326+
}
327+
328+
if (null === $this->document) {
329+
$this->document = $node->ownerDocument;
330+
}
331+
332332
parent::attach($node);
333333
}
334334

src/Symfony/Component/Yaml/Parser.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,17 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
375375

376376
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
377377

378+
// Comments must not be removed inside a block scalar
379+
$removeCommentsPattern = '~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~';
380+
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
381+
378382
while ($this->moveToNextLine()) {
379383
$indent = $this->getCurrentLineIndentation();
380384

385+
if ($indent === $newIndent) {
386+
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
387+
}
388+
381389
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
382390
$this->moveToPreviousLine();
383391
break;
@@ -388,6 +396,10 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
388396
continue;
389397
}
390398

399+
if ($removeComments && $this->isCurrentLineComment()) {
400+
continue;
401+
}
402+
391403
if ($indent >= $newIndent) {
392404
$data[] = substr($this->currentLine, $newIndent);
393405
} elseif (0 == $indent) {

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

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,32 @@ public function testEmptyValue()
622622
$this->assertEquals(array('hash' => null), Yaml::parse($input));
623623
}
624624

625+
public function testCommentAtTheRootIndent()
626+
{
627+
$this->assertEquals(array(
628+
'services' => array(
629+
'app.foo_service' => array(
630+
'class' => 'Foo',
631+
),
632+
'app/bar_service' => array(
633+
'class' => 'Bar',
634+
),
635+
),
636+
), Yaml::parse(<<<EOF
637+
# comment 1
638+
services:
639+
# comment 2
640+
# comment 3
641+
app.foo_service:
642+
class: Foo
643+
# comment 4
644+
# comment 5
645+
app/bar_service:
646+
class: Bar
647+
EOF
648+
));
649+
}
650+
625651
public function testStringBlockWithComments()
626652
{
627653
$this->assertEquals(array('content' => <<<EOT
@@ -679,43 +705,6 @@ public function testFoldedStringBlockWithComments()
679705
));
680706
}
681707

682-
public function testSecondLevelFoldedStringBlockWithComments()
683-
{
684-
$this->assertEquals(array(
685-
'pages' => array(
686-
array(
687-
'title' => 'some title',
688-
'content' => <<<EOT
689-
# comment 1
690-
header
691-
692-
# comment 2
693-
<body>
694-
<h1>title</h1>
695-
</body>
696-
697-
footer # comment3
698-
EOT
699-
),
700-
),
701-
), Yaml::parse(<<<EOF
702-
pages:
703-
-
704-
title: some title
705-
content: |
706-
# comment 1
707-
header
708-
709-
# comment 2
710-
<body>
711-
<h1>title</h1>
712-
</body>
713-
714-
footer # comment3
715-
EOF
716-
));
717-
}
718-
719708
public function testNestedFoldedStringBlockWithComments()
720709
{
721710
$this->assertEquals(array(array(

0 commit comments

Comments
 (0)