@@ -161,13 +161,13 @@ private function doParse(string $value, int $flags)
161
161
Inline::initialize ($ flags , $ this ->getRealCurrentLineNb (), $ this ->filename );
162
162
163
163
$ isRef = $ mergeNode = false ;
164
- if (self ::preg_match ('#^\-((?P<leadspaces>\s+)(?P<value>.+))?$#u ' , rtrim ($ this ->currentLine ), $ values )) {
164
+ if (' - ' === $ this -> currentLine [ 0 ] && self ::preg_match ('#^\-((?P<leadspaces>\s+)(?P<value>.+))?$#u ' , rtrim ($ this ->currentLine ), $ values )) {
165
165
if ($ context && 'mapping ' == $ context ) {
166
166
throw new ParseException ('You cannot define a sequence item when in a mapping ' , $ this ->getRealCurrentLineNb () + 1 , $ this ->currentLine , $ this ->filename );
167
167
}
168
168
$ context = 'sequence ' ;
169
169
170
- if (isset ($ values ['value ' ]) && self ::preg_match ('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u ' , $ values ['value ' ], $ matches )) {
170
+ if (isset ($ values ['value ' ]) && ' & ' === $ values [ ' value ' ][ 0 ] && self ::preg_match ('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u ' , $ values ['value ' ], $ matches )) {
171
171
$ isRef = $ matches ['ref ' ];
172
172
$ values ['value ' ] = $ matches ['value ' ];
173
173
}
@@ -229,7 +229,7 @@ private function doParse(string $value, int $flags)
229
229
$ key = (string ) $ key ;
230
230
}
231
231
232
- if ('<< ' === $ key && (!isset ($ values ['value ' ]) || !self ::preg_match ('#^&(?P<ref>[^ ]+)#u ' , $ values ['value ' ], $ refMatches ))) {
232
+ if ('<< ' === $ key && (!isset ($ values ['value ' ]) || ' & ' !== $ values [ ' value ' ][ 0 ] || !self ::preg_match ('#^&(?P<ref>[^ ]+)#u ' , $ values ['value ' ], $ refMatches ))) {
233
233
$ mergeNode = true ;
234
234
$ allowOverwrite = true ;
235
235
if (isset ($ values ['value ' ][0 ]) && '* ' === $ values ['value ' ][0 ]) {
@@ -286,7 +286,7 @@ private function doParse(string $value, int $flags)
286
286
$ data += $ parsed ; // array union
287
287
}
288
288
}
289
- } elseif ('<< ' !== $ key && isset ($ values ['value ' ]) && self ::preg_match ('#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u ' , $ values ['value ' ], $ matches )) {
289
+ } elseif ('<< ' !== $ key && isset ($ values ['value ' ]) && ' & ' === $ values [ ' value ' ][ 0 ] && self ::preg_match ('#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u ' , $ values ['value ' ], $ matches )) {
290
290
$ isRef = $ matches ['ref ' ];
291
291
$ values ['value ' ] = $ matches ['value ' ];
292
292
}
@@ -671,7 +671,7 @@ private function parseValue(string $value, int $flags, string $context)
671
671
return $ this ->refs [$ value ];
672
672
}
673
673
674
- if (self ::preg_match ('/^(?: ' .self ::TAG_PATTERN .' +)? ' .self ::BLOCK_SCALAR_HEADER_PATTERN .'$/ ' , $ value , $ matches )) {
674
+ if (\in_array ( $ value [ 0 ], array ( ' ! ' , ' | ' , ' > ' ), true ) && self ::preg_match ('/^(?: ' .self ::TAG_PATTERN .' +)? ' .self ::BLOCK_SCALAR_HEADER_PATTERN .'$/ ' , $ value , $ matches )) {
675
675
$ modifiers = isset ($ matches ['modifiers ' ]) ? $ matches ['modifiers ' ] : '' ;
676
676
677
677
$ data = $ this ->parseBlockScalar ($ matches ['separator ' ], preg_replace ('#\d+# ' , '' , $ modifiers ), (int ) abs ($ modifiers ));
@@ -773,8 +773,10 @@ private function parseBlockScalar(string $style, string $chomping = '', int $ind
773
773
774
774
// determine indentation if not specified
775
775
if (0 === $ indentation ) {
776
- if (self ::preg_match ('/^ +/ ' , $ this ->currentLine , $ matches )) {
777
- $ indentation = \strlen ($ matches [0 ]);
776
+ $ currentLineLength = \strlen ($ this ->currentLine );
777
+
778
+ for ($ i = 0 ; $ i < $ currentLineLength && ' ' === $ this ->currentLine [$ i ]; ++$ i ) {
779
+ ++$ indentation ;
778
780
}
779
781
}
780
782
@@ -1009,7 +1011,7 @@ private function isStringUnIndentedCollectionItem(): bool
1009
1011
*/
1010
1012
private function isBlockScalarHeader (): bool
1011
1013
{
1012
- return (bool ) self ::preg_match ('~ ' .self ::BLOCK_SCALAR_HEADER_PATTERN .'$~ ' , $ this ->currentLine );
1014
+ return '' !== $ this -> currentLine && (bool ) self ::preg_match ('~ ' .self ::BLOCK_SCALAR_HEADER_PATTERN .'$~ ' , $ this ->currentLine );
1013
1015
}
1014
1016
1015
1017
/**
0 commit comments