@@ -343,7 +343,11 @@ private function getCurrentLineIndentation()
343
343
private function getNextEmbedBlock ($ indentation = null , $ inSequence = false )
344
344
{
345
345
$ oldLineIndentation = $ this ->getCurrentLineIndentation ();
346
- $ insideBlockScalar = $ this ->isBlockScalarHeader ();
346
+ $ blockScalarIndentations = array ();
347
+
348
+ if ($ this ->isBlockScalarHeader ()) {
349
+ $ blockScalarIndentations [] = $ this ->getCurrentLineIndentation ();
350
+ }
347
351
348
352
if (!$ this ->moveToNextLine ()) {
349
353
return ;
@@ -380,17 +384,26 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
380
384
381
385
$ isItUnindentedCollection = $ this ->isStringUnIndentedCollectionItem ();
382
386
383
- if (! $ insideBlockScalar ) {
384
- $ insideBlockScalar = $ this ->isBlockScalarHeader ();
387
+ if (empty ( $ blockScalarIndentations ) && $ this -> isBlockScalarHeader () ) {
388
+ $ blockScalarIndentations [] = $ this ->getCurrentLineIndentation ();
385
389
}
386
390
387
391
$ previousLineIndentation = $ this ->getCurrentLineIndentation ();
388
392
389
393
while ($ this ->moveToNextLine ()) {
390
394
$ indent = $ this ->getCurrentLineIndentation ();
391
395
392
- if (!$ insideBlockScalar && $ indent === $ previousLineIndentation ) {
393
- $ insideBlockScalar = $ this ->isBlockScalarHeader ();
396
+ // terminate all block scalars that are more indented than the current line
397
+ if (!empty ($ blockScalarIndentations ) && $ indent < $ previousLineIndentation && trim ($ this ->currentLine ) !== '' ) {
398
+ foreach ($ blockScalarIndentations as $ key => $ blockScalarIndentation ) {
399
+ if ($ blockScalarIndentation >= $ this ->getCurrentLineIndentation ()) {
400
+ unset($ blockScalarIndentations [$ key ]);
401
+ }
402
+ }
403
+ }
404
+
405
+ if (empty ($ blockScalarIndentations ) && !$ this ->isCurrentLineComment () && $ this ->isBlockScalarHeader ()) {
406
+ $ blockScalarIndentations [] = $ this ->getCurrentLineIndentation ();
394
407
}
395
408
396
409
$ previousLineIndentation = $ indent ;
@@ -406,7 +419,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
406
419
}
407
420
408
421
// we ignore "comment" lines only when we are not inside a scalar block
409
- if (! $ insideBlockScalar && $ this ->isCurrentLineComment ()) {
422
+ if (empty ( $ blockScalarIndentations ) && $ this ->isCurrentLineComment ()) {
410
423
continue ;
411
424
}
412
425
@@ -564,7 +577,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0)
564
577
$ previousLineIndented = false ;
565
578
$ previousLineBlank = false ;
566
579
567
- for ($ i = 0 ; $ i < count ($ blockLines ); $ i ++ ) {
580
+ for ($ i = 0 ; $ i < count ($ blockLines ); ++ $ i ) {
568
581
if ('' === $ blockLines [$ i ]) {
569
582
$ text .= "\n" ;
570
583
$ previousLineIndented = false ;
@@ -659,7 +672,7 @@ private function isCurrentLineComment()
659
672
//checking explicitly the first char of the trim is faster than loops or strpos
660
673
$ ltrimmedLine = ltrim ($ this ->currentLine , ' ' );
661
674
662
- return $ ltrimmedLine [0 ] === '# ' ;
675
+ return '' !== $ ltrimmedLine && $ ltrimmedLine [0 ] === '# ' ;
663
676
}
664
677
665
678
/**
0 commit comments