@@ -2362,6 +2362,39 @@ public function testParseValueWithNegativeModifiers()
2362
2362
$ this ->parser ->parse ($ yaml )
2363
2363
);
2364
2364
}
2365
+
2366
+ /**
2367
+ * This is a regression test for a bug where a YAML block with a nested multiline string using | was parsed without
2368
+ * a trailing \n when a shorter YAML document was parsed before.
2369
+ *
2370
+ * When a shorter document was parsed before, the nested string did not have a \n at the end of the string, because
2371
+ * the Parser thought it was the end of the file, even though it is not.
2372
+ */
2373
+ public function testParsingMultipleDocuments ()
2374
+ {
2375
+ $ shortDocument = 'foo: bar ' ;
2376
+ $ longDocument = <<<YAML
2377
+ a:
2378
+ b: |
2379
+ row
2380
+ row2
2381
+ c: d
2382
+ YAML ;
2383
+
2384
+ $ expected = ['a ' => ['b ' => "row \nrow2 \n" ], 'c ' => 'd ' ];
2385
+
<
8F21
td data-grid-cell-id="diff-e08f7eceb47aaa5984137cc6f3ea19b585dc972d3fafc005dd98234c04e60d2d-2364-2386-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
2386
+ // The parser was not used before, so there is a new line after row2
2387
+ $ this ->assertSame ($ expected , $ this ->parser ->parse ($ longDocument ));
2388
+
2389
+ $ parser = new Parser ();
2390
+ // The first parsing set and fixed the totalNumberOfLines in the Parser before, so parsing the short document here
2391
+ // to reproduce the issue. If the issue would not have been fixed, the next assertion will fail
2392
+ $ parser ->parse ($ shortDocument );
2393
+
2394
+ // After the total number of lines has been rset the result will be the same as if a new parser was used
2395
+ // (before, there was no \n after row2)
2396
+ $ this ->assertSame ($ expected , $ parser ->parse ($ longDocument ));
2397
+ }
2365
2398
}
2366
2399
2367
2400
class B
0 commit comments