File tree 2 files changed +51
-1
lines changed
Filter options
src/Symfony/Component/Yaml
2 files changed +51
-1
lines changed
Original file line number Diff line number Diff line change @@ -402,7 +402,7 @@ private function doParse($value, $flags)
402
402
throw new ParseException ('Multiple documents are not supported. ' , $ this ->currentLineNb + 1 , $ this ->currentLine , $ this ->filename );
403
403
}
404
404
405
- if (isset ($ this ->currentLine [1 ]) && '? ' === $ this ->currentLine [0 ] && ' ' === $ this ->currentLine [1 ]) {
405
+ if ($ deprecatedUsage = ( isset ($ this ->currentLine [1 ]) && '? ' === $ this ->currentLine [0 ] && ' ' === $ this ->currentLine [1 ]) ) {
406
406
@trigger_error ($ this ->getDeprecationMessage ('Starting an unquoted string with a question mark followed by a space is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. ' ), E_USER_DEPRECATED );
407
407
}
408
408
@@ -427,6 +427,10 @@ private function doParse($value, $flags)
427
427
$ value = '' ;
428
428
429
429
foreach ($ this ->lines as $ line ) {
430
+ // If the indentation is not consistent at offset 0, it is to be considered as a ParseError
431
+ if (0 === $ this ->offset && !$ deprecatedUsage && isset ($ line [0 ]) && ' ' === $ line [0 ]) {
432
+ throw new ParseException ('Unable to parse. ' , $ this ->getRealCurrentLineNb () + 1 , $ this ->currentLine , $ this ->filename );
433
+ }
430
434
if ('' === trim ($ line )) {
431
435
$ value .= "\n" ;
432
436
} elseif (!$ previousLineWasNewline && !$ previousLineWasTerminatedWithBackslash ) {
Original file line number Diff line number Diff line change @@ -812,6 +812,41 @@ public function testNonStringFollowedByCommentEmbeddedInMapping()
812
812
$ this ->assertSame ($ expected , $ this ->parser ->parse ($ yaml ));
813
813
}
814
814
815
+ public function getParseExceptionNotAffectedMultiLineStringLastResortParsing ()
816
+ {
817
+ $ tests = array ();
818
+
819
+ $ yaml = <<<'EOT'
820
+ a
821
+ b:
822
+ EOT;
823
+ $ tests ['parse error on first line ' ] = array ($ yaml );
824
+
825
+ $ yaml = <<<'EOT'
826
+ a
827
+
828
+ b
829
+ c:
830
+ EOT;
831
+ $ tests ['parse error due to inconsistent indentation ' ] = array ($ yaml );
832
+
833
+ $ yaml = <<<'EOT'
834
+ & * ! | > ' " % @ ` #, { asd a;sdasd }-@^qw3
835
+ EOT;
836
+ $ tests ['symfony/symfony/issues/22967#issuecomment-322067742 ' ] = array ($ yaml );
837
+
838
+ return $ tests ;
839
+ }
840
+
841
+ /**
842
+ * @dataProvider getParseExceptionNotAffectedMultiLineStringLastResortParsing
843
+ * @expectedException \Symfony\Component\Yaml\Exception\ParseException
844
+ */
845
+ public function testParseExceptionNotAffectedByMultiLineStringLastResortParsing ($ yaml )
846
+ {
847
+ $ this ->parser ->parse ($ yaml );
848
+ }
849
+
815
850
public function testMultiLineStringLastResortParsing ()
816
851
{
817
852
$ yaml = <<<'EOT'
@@ -825,6 +860,17 @@ public function testMultiLineStringLastResortParsing()
825
860
);
826
861
827
862
$ this ->assertSame ($ expected , $ this ->parser ->parse ($ yaml ));
863
+
864
+ $ yaml = <<<'EOT'
865
+ a:
866
+ b
867
+ c
868
+ EOT;
869
+ $ expected = array (
870
+ 'a ' => 'b c ' ,
871
+ );
872
+
873
+ $ this ->assertSame ($ expected , $ this ->parser ->parse ($ yaml ));
828
874
}
829
875
830
876
/**
You can’t perform that action at this time.
0 commit comments