@@ -750,54 +750,54 @@ private function parseValue(string $value, int $flags, string $context)
750
750
return Inline::parse ($ this ->lexInlineSequence ($ cursor ), $ flags , $ this ->refs );
751
751
}
752
752
753
- $ quotation = '' !== $ value && ('" ' === $ value [0 ] || "' " === $ value [0 ]) ? $ value [0 ] : null ;
754
-
755
- // do not take following lines into account when the current line is a quoted single line value
756
- if (null !== $ quotation && self ::preg_match ('/^ ' .$ quotation .'.* ' .$ quotation .'(\s*#.*)?$/ ' , $ value )) {
757
- return Inline::parse ($ value , $ flags , $ this ->refs );
758
- }
753
+ switch ($ value [0 ]) {
754
+ case '" ' :
755
+ case "' " :
756
+ $ cursor = \strlen ($ this ->currentLine ) - \strlen ($ value );
757
+ $ parsedValue = Inline::parse ($ this ->lexInlineQuotedString ($ cursor ), $ flags , $ this ->refs );
758
+
759
+ if (isset ($ this ->currentLine [$ cursor ]) && preg_replace ('/\s*#.*$/A ' , '' , substr ($ this ->currentLine , $ cursor ))) {
760
+ throw new ParseException (sprintf ('Unexpected characters near "%s". ' , substr ($ this ->currentLine , $ cursor )));
761
+ }
759
762
760
- $ lines = [];
763
+ return $ parsedValue ;
764
+ default :
765
+ $ lines = [];
761
766
762
- while ($ this ->moveToNextLine ()) {
763
- // unquoted strings end before the first unindented line
764
- if ( null === $ quotation && 0 === $ this ->getCurrentLineIndentation ()) {
765
- $ this ->moveToPreviousLine ();
767
+ while ($ this ->moveToNextLine ()) {
768
+ // unquoted strings end before the first unindented line
769
+ if ( 0 === $ this ->getCurrentLineIndentation ()) {
770
+ $ this ->moveToPreviousLine ();
766
771
767
- break ;
768
- }
772
+ break ;
773
+ }
769
774
770
- $ lines [] = trim ($ this ->currentLine );
775
+ $ lines [] = trim ($ this ->currentLine );
776
+ }
771
777
772
- // quoted string values end with a line that is terminated with the quotation character
773
- $ escapedLine = str_replace (['\\\\' , '\\" ' ], '' , $ this ->currentLine );
774
- if ('' !== $ escapedLine && substr ($ escapedLine , -1 ) === $ quotation ) {
775
- break ;
776
- }
777
- }
778
+ for ($ i = 0 , $ linesCount = \count ($ lines ), $ previousLineBlank = false ; $ i < $ linesCount ; ++$ i ) {
779
+ if ('' === $ lines [$ i ]) {
780
+ $ value .= "\n" ;
781
+ $ previousLineBlank = true ;
782
+ } elseif ($ previousLineBlank ) {
783
+ $ value .= $ lines [$ i ];
784
+ $ previousLineBlank = false ;
785
+ } else {
786
+ $ value .= ' ' .$ lines [$ i ];
787
+ $ previousLineBlank = false ;
788
+ }
789
+ }
778
790
779
- for ($ i = 0 , $ linesCount = \count ($ lines ), $ previousLineBlank = false ; $ i < $ linesCount ; ++$ i ) {
780
- if ('' === $ lines [$ i ]) {
781
- $ value .= "\n" ;
782
- $ previousLineBlank = true ;
783
- } elseif ($ previousLineBlank ) {
784
- $ value .= $ lines [$ i ];
785
- $ previousLineBlank = false ;
786
- } else {
787
- $ value .= ' ' .$ lines [$ i ];
788
- $ previousLineBlank = false ;
789
- }
790
- }
791
+ Inline::$ parsedLineNumber = $ this ->getRealCurrentLineNb ();
791
792
792
- Inline::$ parsedLineNumber = $ this ->getRealCurrentLineNb ( );
793
+ $ parsedValue = Inline::parse ( $ value , $ flags , $ this ->refs );
793
794
794
- $ parsedValue = Inline::parse ($ value , $ flags , $ this ->refs );
795
+ if ('mapping ' === $ context && \is_string ($ parsedValue ) && '" ' !== $ value [0 ] && "' " !== $ value [0 ] && '[ ' !== $ value [0 ] && '{ ' !== $ value [0 ] && '! ' !== $ value [0 ] && false !== strpos ($ parsedValue , ': ' )) {
796
+ throw new ParseException ('A colon cannot be used in an unquoted mapping value. ' , $ this ->getRealCurrentLineNb () + 1 , $ value , $ this ->filename );
797
+ }
795
798
796
- if ('mapping ' === $ context && \is_string ($ parsedValue ) && '" ' !== $ value [0 ] && "' " !== $ value [0 ] && '[ ' !== $ value [0 ] && '{ ' !== $ value [0 ] && '! ' !== $ value [0 ] && false !== strpos ($ parsedValue , ': ' )) {
797
- throw new ParseException ('A colon cannot be used in an unquoted mapping value. ' , $ this ->getRealCurrentLineNb () + 1 , $ value , $ this ->filename );
799
+ return $ parsedValue ;
798
800
}
799
-
800
- return $ parsedValue ;
801
801
} catch (ParseException $ e ) {
802
802
$ e ->setParsedLine ($ this ->getRealCurrentLineNb () + 1 );
803
803
$ e ->setSnippet ($ this ->currentLine );
@@ -1154,8 +1154,13 @@ private function lexInlineQuotedString(int &$cursor = 0): string
1154
1154
1155
1155
$ previousLineWasNewline = true ;
1156
1156
$ previousLineWasTerminatedWithBackslash = false ;
1157
+ $ lineNumber = 0 ;
1157
1158
1158
1159
do {
1160
+ if (++$ lineNumber > 1 ) {
1161
+ $ cursor += strspn ($ this ->currentLine , ' ' , $ cursor );
1162
+ }
1163
+
1159
1164
if ($ this ->isCurrentLineBlank ()) {
1160
1165
$ value .= "\n" ;
1161
1166
} elseif (!$ previousLineWasNewline && !$ previousLineWasTerminatedWithBackslash ) {
0 commit comments