@@ -269,10 +269,11 @@ private static function dumpNull(int $flags): string
269
269
*
270
270
* @throws ParseException When malformed inline YAML string is parsed
271
271
*/
272
- public static function parseScalar (string $ scalar , int $ flags = 0 , array $ delimiters = null , int &$ i = 0 , bool $ evaluate = true , array &$ references = [])
272
+ public static function parseScalar (string $ scalar , int $ flags = 0 , array $ delimiters = null , int &$ i = 0 , bool $ evaluate = true , array &$ references = [], bool & $ isQuoted = null )
273
273
{
274
274
if (\in_array ($ scalar [$ i ], ['" ' , "' " ])) {
275
275
// quoted scalar
276
+ $ isQuoted = true ;
276
277
$ output = self ::parseQuotedScalar ($ scalar , $ i );
277
278
278
279
if (null !== $ delimiters ) {
@@ -286,6 +287,8 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
286
287
}
287
288
} else {
288
289
// "normal" string
290
+ $ isQuoted = false ;
291
+
289
292
if (!$ delimiters ) {
290
293
$ output = substr ($ scalar , $ i );
291
294
$ i += \strlen ($ output );
@@ -308,7 +311,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
308
311
}
309
312
310
313
if ($ evaluate ) {
311
- $ output = self ::evaluateScalar ($ output , $ flags , $ references );
314
+ $ output = self ::evaluateScalar ($ output , $ flags , $ references, $ isQuoted );
312
315
}
313
316
}
314
317
@@ -320,7 +323,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
320
323
*
321
324
* @throws ParseException When malformed inline YAML string is parsed
322
325
*/
323
- private static function parseQuotedScalar (string $ scalar , int &$ i ): string
326
+ private static function parseQuotedScalar (string $ scalar , int &$ i = 0 ): string
324
327
{
325
328
if (!Parser::preg_match ('/ ' .self ::REGEX_QUOTED_STRING .'/Au ' , substr ($ scalar , $ i ), $ match )) {
326
329
throw new ParseException (sprintf ('Malformed inline YAML string: "%s". ' , substr ($ scalar , $ i )), self ::$ parsedLineNumber + 1 , $ scalar , self ::$ parsedFilename );
@@ -373,8 +376,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
373
376
$ value = self ::parseMapping ($ sequence , $ flags , $ i , $ references );
374
377
break ;
375
378
default :
376
- $ isQuoted = \in_array ($ sequence [$ i ], ['" ' , "' " ]);
377
- $ value = self ::parseScalar ($ sequence , $ flags , [', ' , '] ' ], $ i , null === $ tag , $ references );
379
+ $ value = self ::parseScalar ($ sequence , $ flags , [', ' , '] ' ], $ i , null === $ tag , $ references , $ isQuoted );
378
380
379
381
// the value can be an array if a reference has been resolved to an array var
380
382
if (\is_string ($ value ) && !$ isQuoted && false !== strpos ($ value , ': ' )) {
@@ -521,8 +523,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
521
523
}
522
524
break ;
523
525
default :
524
- $ isValueQuoted = \in_array ($ mapping [$ i ], ['" ' , "' " ]);
525
- $ value = self ::parseScalar ($ mapping , $ flags , [', ' , '} ' , "\n" ], $ i , null === $ tag , $ references );
526
+ $ value = self ::parseScalar ($ mapping , $ flags , [', ' , '} ' , "\n" ], $ i , null === $ tag , $ references , $ isValueQuoted );
526
527
// Spec: Keys MUST be unique; first one wins.
527
528
// Parser cannot abort this mapping earlier, since lines
528
529
// are processed sequentially.
@@ -561,8 +562,9 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
561
562
*
562
563
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
563
564
*/
564
- private static function evaluateScalar (string $ scalar , int $ flags , array &$ references = [])
565
+ private static function evaluateScalar (string $ scalar , int $ flags , array &$ references = [], bool & $ isQuotedString = null )
565
566
{
567
+ $ isQuotedString = false ;
566
568
$ scalar = trim ($ scalar );
567
569
$ scalarLower = strtolower ($ scalar );
568
570
@@ -597,7 +599,14 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
597
599
case '! ' === $ scalar [0 ]:
598
600
switch (true ) {
599
601
case 0 === strpos ($ scalar , '!!str ' ):
600
- return (string ) substr ($ scalar , 6 );
602
+ $ s = (string ) substr ($ scalar , 6 );
603
+
604
+ if (\in_array ($ s [0 ] ?? '' , ['" ' , "' " ], true )) {
605
+ $ isQuotedString = true ;
606
+ $ s = self ::parseQuotedScalar ($ s );
607
+ }
608
+
609
+ return $ s ;
601
610
case 0 === strpos ($ scalar , '! ' ):
602
611
return substr ($ scalar , 2 );
603
612
case 0 === strpos ($ scalar , '!php/object ' ):
0 commit comments