@@ -303,7 +303,11 @@ private function getCurrentLineIndentation()
303
303
private function getNextEmbedBlock ($ indentation = null , $ inSequence = false )
304
304
{
305
305
$ oldLineIndentation = $ this ->getCurrentLineIndentation ();
306
- $ insideBlockScalar = $ this ->isBlockScalarHeader ();
306
+ $ blockScalarIndentations = array ();
307
+
308
+ if ($ this ->isBlockScalarHeader ()) {
309
+ $ blockScalarIndentations [] = $ this ->getCurrentLineIndentation ();
310
+ }
307
311
308
312
if (!$ this ->moveToNextLine ()) {
309
313
return ;
@@ -340,17 +344,26 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
340
344
341
345
$ isItUnindentedCollection = $ this ->isStringUnIndentedCollectionItem ();
342
346
343
- if (! $ insideBlockScalar ) {
344
- $ insideBlockScalar = $ this ->isBlockScalarHeader ();
347
+ if (empty ( $ blockScalarIndentations ) && $ this -> isBlockScalarHeader () ) {
348
+ $ blockScalarIndentations [] = $ this ->getCurrentLineIndentation ();
345
349
}
346
350
347
351
$ previousLineIndentation = $ this ->getCurrentLineIndentation ();
348
352
349
353
while ($ this ->moveToNextLine ()) {
350
354
$ indent = $ this ->getCurrentLineIndentation ();
351
355
352
- if (!$ insideBlockScalar && $ indent === $ previousLineIndentation ) {
353
- $ insideBlockScalar = $ this ->isBlockScalarHeader ();
356
+ // terminate all block scalars that are more indented than the current line
357
+ if (!empty ($ blockScalarIndentations ) && $ indent < $ previousLineIndentation && trim ($ this ->currentLine ) !== '' ) {
358
+ foreach ($ blockScalarIndentations as $ key => $ blockScalarIndentation ) {
359
+ if ($ blockScalarIndentation >= $ this ->getCurrentLineIndentation ()) {
360
+ unset($ blockScalarIndentations [$ key ]);
361
+ }
362
+ }
363
+ }
364
+
365
+ if (empty ($ blockScalarIndentations ) && !$ this ->isCurrentLineComment () && $ this ->isBlockScalarHeader ()) {
366
+ $ blockScalarIndentations [] = $ this ->getCurrentLineIndentation ();
354
367
}
355
368
356
369
$ previousLineIndentation = $ indent ;
@@ -366,7 +379,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
366
379
}
367
380
368
381
// we ignore "comment" lines only when we are not inside a scalar block
369
- if (! $ insideBlockScalar && $ this ->isCurrentLineComment ()) {
382
+ if (empty ( $ blockScalarIndentations ) && $ this ->isCurrentLineComment ()) {
370
383
continue ;
371
384
}
372
385
@@ -523,7 +536,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0)
523
536
$ previousLineIndented = false ;
524
537
$ previousLineBlank = false ;
525
538
526
- for ($ i = 0 ; $ i < count ($ blockLines ); $ i ++ ) {
539
+ for ($ i = 0 ; $ i < count ($ blockLines ); ++ $ i ) {
527
540
if ('' === $ blockLines [$ i ]) {
528
541
$ text .= "\n" ;
529
542
$ previousLineIndented = false ;
@@ -618,7 +631,7 @@ private function isCurrentLineComment()
618
631
//checking explicitly the first char of the trim is faster than loops or strpos
619
632
$ ltrimmedLine = ltrim ($ this ->currentLine , ' ' );
620
633
621
- return $ ltrimmedLine [0 ] === '# ' ;
634
+ return '' !== $ ltrimmedLine && $ ltrimmedLine [0 ] === '# ' ;
622
635
}
623
636
624
637
/**
0 commit comments