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