@@ -1760,25 +1760,22 @@ public function testParseMultiLineUnquotedString()
17601760 $ this ->assertSame (['foo ' => 'bar baz foobar foo ' , 'bar ' => 'baz ' ], $ this ->parser ->parse ($ yaml ));
17611761 }
17621762
1763- #[DataProvider('unquotedStringWithTrailingComment ' )]
1764- public function testUnquotedMultilineScalarIgnoresComments (string $ yaml , array $ expected )
1763+ #[DataProvider('getUnquotedMultilineScalarHandlesCommentsAndBlanksData ' )]
1764+ public function testUnquotedMultilineScalarHandlesCommentsAndBlanks (string $ yaml , array $ expected )
17651765 {
17661766 $ this ->assertSame ($ expected , $ this ->parser ->parse ($ yaml ));
17671767 }
17681768
1769- public static function getUnquotedMultilineScalarIgnoresCommentsData ()
1769+ public static function getUnquotedMultilineScalarHandlesCommentsAndBlanksData ()
17701770 {
1771- yield 'comments interspersed ' => [
1771+ yield 'comments interspersed stops scalar ' => [
17721772 <<<YAML
17731773 key: unquoted
1774- # this comment should be ignored
1775- next line
1776- # another comment
1777- final line
1774+ # this comment terminates
17781775 another_key: works
17791776 YAML ,
17801777 [
1781- 'key ' => 'unquoted next line final line ' ,
1778+ 'key ' => 'unquoted ' ,
17821779 'another_key ' => 'works ' ,
17831780 ],
17841781 ];
@@ -1796,17 +1793,16 @@ public static function getUnquotedMultilineScalarIgnoresCommentsData()
17961793 ],
17971794 ];
17981795
1799- yield 'blank lines and comments ' => [
1796+ yield 'blank lines are preserved and comment stops scalar ' => [
18001797 <<<YAML
18011798 key: unquoted
18021799 next line
18031800
1804- # this comment should be ignored
1805- final line
1801+ # this comment terminates the scalar
18061802 another_key: works
18071803 YAML ,
18081804 [
1809- 'key ' => " unquoted next line \n final line " ,
1805+ 'key ' => ' unquoted next line ' ,
18101806 'another_key ' => 'works ' ,
18111807 ],
18121808 ];
@@ -1825,6 +1821,21 @@ public static function getUnquotedMultilineScalarIgnoresCommentsData()
18251821 ];
18261822 }
18271823
1824+ public function testUnquotedMultilineScalarThrowsOnOrphanedLineAfterComment ()
1825+ {
1826+ $ this ->expectException (ParseException::class);
1827+ $ this ->expectExceptionMessage ('Unable to parse at line 3 (near " next line") ' );
1828+
1829+ $ yaml = <<<YAML
1830+ key: unquoted
1831+ # this comment terminates
1832+ next line
1833+ another_key: works
1834+ YAML ;
1835+
1836+ $ this ->parser ->parse ($ yaml );
1837+ }
1838+
18281839 #[DataProvider('unquotedStringWithTrailingComment ' )]
18291840 public function testParseMultiLineUnquotedStringWithTrailingComment (string $ yaml , array $ expected )
18301841 {
0 commit comments