File tree Expand file tree Collapse file tree 2 files changed +61
-2
lines changed
src/Symfony/Component/Yaml Expand file tree Collapse file tree 2 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -304,14 +304,16 @@ private function getNextEmbedBlock($indentation = null)
304
304
305
305
$ isItUnindentedCollection = $ this ->isStringUnIndentedCollectionItem ($ this ->currentLine );
306
306
307
- while ($ this ->moveToNextLine ()) {
307
+ // We are in string block (ie. after a line ending with "|")
308
+ $ removeComments = !preg_match ('~(.*)\|[\s]*$~ ' , $ this ->currentLine );
308
309
310
+ while ($ this ->moveToNextLine ()) {
309
311
if ($ isItUnindentedCollection && !$ this ->isStringUnIndentedCollectionItem ($ this ->currentLine )) {
310
312
$ this ->moveToPreviousLine ();
311
313
break ;
312
314
}
313
315
314
- if ($ this ->isCurrentLineEmpty ()) {
316
+ if ($ removeComments && $ this ->isCurrentLineEmpty () || $ this -> isCurrentLineBlank ()) {
315
317
if ($ this ->isCurrentLineBlank ()) {
316
318
$ data [] = substr ($ this ->currentLine , $ newIndent );
317
319
}
Original file line number Diff line number Diff line change @@ -522,6 +522,63 @@ public function testEmptyValue()
522
522
523
523
$ this ->assertEquals (array ('hash ' => null ), Yaml::parse ($ input ));
524
524
}
525
+
526
+ public function testStringBlockWithComments ()
527
+ {
528
+ $ this ->assertEquals (array ('content ' => <<<EOT
529
+ # comment 1
530
+ header
531
+
532
+ # comment 2
533
+ <body>
534
+ <h1>title</h1>
535
+ </body>
536
+
537
+ footer # comment3
538
+ EOT
539
+ ), Yaml::parse (<<<EOF
540
+ content: |
541
+ # comment 1
542
+ header
543
+
544
+ # comment 2
545
+ <body>
546
+ <h1>title</h1>
547
+ </body>
548
+
549
+ footer # comment3
550
+ EOF
551
+ ));
552
+ }
553
+
554
+ public function testNestedStringBlockWithComments ()
555
+ {
556
+ $ this ->assertEquals (array (array ('content ' => <<<EOT
557
+ # comment 1
558
+ header
559
+
560
+ # comment 2
561
+ <body>
562
+ <h1>title</h1>
563
+ </body>
564
+
565
+ footer # comment3
566
+ EOT
567
+ )), Yaml::parse (<<<EOF
568
+ -
569
+ content: |
570
+ # comment 1
571
+ header
572
+
573
+ # comment 2
574
+ <body>
575
+ <h1>title</h1>
576
+ </body>
577
+
578
+ footer # comment3
579
+ EOF
580
+ ));
581
+ }
525
582
}
526
583
527
584
class B
You can’t perform that action at this time.
0 commit comments