@@ -247,10 +247,11 @@ private static function dumpNull(int $flags): string
247
247
*
248
248
* @throws ParseException When malformed inline YAML string is parsed
249
249
*/
250
- public static function parseScalar (string $ scalar , int $ flags = 0 , array $ delimiters = null , int &$ i = 0 , bool $ evaluate = true , array &$ references = []): mixed
250
+ public static function parseScalar (string $ scalar , int $ flags = 0 , array $ delimiters = null , int &$ i = 0 , bool $ evaluate = true , array &$ references = [], bool & $ isQuoted = null ): mixed
251
251
{
252
252
if (\in_array ($ scalar [$ i ], ['" ' , "' " ], true )) {
253
253
// quoted scalar
254
+ $ isQuoted = true ;
254
255
$ output = self ::parseQuotedScalar ($ scalar , $ i );
255
256
256
257
if (null !== $ delimiters ) {
@@ -264,6 +265,8 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
264
265
}
265
266
} else {
266
267
// "normal" string
268
+ $ isQuoted = false ;
269
+
267
270
if (!$ delimiters ) {
268
271
$ output = substr ($ scalar , $ i );
269
272
$ i += \strlen ($ output );
@@ -286,7 +289,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
286
289
}
287
290
288
291
if ($ evaluate ) {
289
- $ output = self ::evaluateScalar ($ output , $ flags , $ references );
292
+ $ output = self ::evaluateScalar ($ output , $ flags , $ references, $ isQuoted );
290
293
}
291
294
}
292
295
@@ -298,7 +301,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
298
301
*
299
302
* @throws ParseException When malformed inline YAML string is parsed
300
303
*/
301
- private static function parseQuotedScalar (string $ scalar , int &$ i ): string
304
+ private static function parseQuotedScalar (string $ scalar , int &$ i = 0 ): string
302
305
{
303
306
if (!Parser::preg_match ('/ ' .self ::REGEX_QUOTED_STRING .'/Au ' , substr ($ scalar , $ i ), $ match )) {
304
307
throw new ParseException (sprintf ('Malformed inline YAML string: "%s". ' , substr ($ scalar , $ i )), self ::$ parsedLineNumber + 1 , $ scalar , self ::$ parsedFilename );
@@ -351,8 +354,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
351
354
$ value = self ::parseMapping ($ sequence , $ flags , $ i , $ references );
352
355
break ;
353
356
default :
354
- $ isQuoted = \in_array ($ sequence [$ i ], ['" ' , "' " ], true );
355
- $ value = self ::parseScalar ($ sequence , $ flags , [', ' , '] ' ], $ i , null === $ tag , $ references );
357
+ $ value = self ::parseScalar ($ sequence , $ flags , [', ' , '] ' ], $ i , null === $ tag , $ references , $ isQuoted );
356
358
357
359
// the value can be an array if a reference has been resolved to an array var
358
360
if (\is_string ($ value ) && !$ isQuoted && false !== strpos ($ value , ': ' )) {
@@ -497,8 +499,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
497
499
}
498
500
break ;
499
501
default :
500
- $ isValueQuoted = \in_array ($ mapping [$ i ], ['" ' , "' " ]);
501
- $ value = self ::parseScalar ($ mapping , $ flags , [', ' , '} ' , "\n" ], $ i , null === $ tag , $ references );
502
+ $ value = self ::parseScalar ($ mapping , $ flags , [', ' , '} ' , "\n" ], $ i , null === $ tag , $ references , $ isValueQuoted );
502
503
// Spec: Keys MUST be unique; first one wins.
503
504
// Parser cannot abort this mapping earlier, since lines
504
505
// are processed sequentially.
@@ -535,8 +536,9 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
535
536
*
536
537
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
537
538
*/
538
- private static function evaluateScalar (string $ scalar , int $ flags , array &$ references = []): mixed
539
+ private static function evaluateScalar (string $ scalar , int $ flags , array &$ references = [], bool & $ isQuotedString = null ): mixed
539
540
{
541
+ $ isQuotedString = false ;
540
542
$ scalar = trim ($ scalar );
541
543
542
544
if (0 === strpos ($ scalar , '* ' )) {
@@ -572,7 +574,14 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
572
574
case '! ' === $ scalar [0 ]:
573
575
switch (true ) {
574
576
case 0 === strpos ($ scalar , '!!str ' ):
575
- return (string ) substr ($ scalar , 6 );
577
+ $ s = (string ) substr ($ scalar , 6 );
578
+
579
+ if (\in_array ($ s [0 ] ?? '' , ['" ' , "' " ], true )) {
580
+ $ isQuotedString = true ;
581
+ $ s = self ::parseQuotedScalar ($ s );
582
+ }
583
+
584
+ return $ s ;
576
585
case 0 === strpos ($ scalar , '! ' ):
577
586
return substr ($ scalar , 2 );
578
587
case 0 === strpos ($ scalar , '!php/object ' ):
0 commit comments