@@ -269,10 +269,11 @@ private static function dumpNull(int $flags): string
269269 *
270270 * @throws ParseException When malformed inline YAML string is parsed
271271 */
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 )
273273 {
274274if (\in_array ($ scalar [$ i ], ['" ' ,"' " ])) {
275275// quoted scalar
276+ $ isQuoted =true ;
276277$ output =self ::parseQuotedScalar ($ scalar ,$ i );
277278
278279if (null !==$ delimiters ) {
@@ -286,6 +287,8 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
286287 }
287288 }else {
288289// "normal" string
290+ $ isQuoted =false ;
291+
289292if (!$ delimiters ) {
290293$ output =substr ($ scalar ,$ i );
291294$ i +=\strlen ($ output );
@@ -308,7 +311,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
308311 }
309312
310313if ($ evaluate ) {
311- $ output =self ::evaluateScalar ($ output ,$ flags ,$ references );
314+ $ output =self ::evaluateScalar ($ output ,$ flags ,$ references, $ isQuoted );
312315 }
313316 }
314317
@@ -320,7 +323,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
320323 *
321324 * @throws ParseException When malformed inline YAML string is parsed
322325 */
323- private static function parseQuotedScalar (string $ scalar ,int &$ i ):string
326+ private static function parseQuotedScalar (string $ scalar ,int &$ i = 0 ):string
324327 {
325328if (!Parser::preg_match ('/ ' .self ::REGEX_QUOTED_STRING .'/Au ' ,substr ($ scalar ,$ i ),$ match )) {
326329throw 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,
373376$ value =self ::parseMapping ($ sequence ,$ flags ,$ i ,$ references );
374377break ;
375378default :
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 );
378380
379381// the value can be an array if a reference has been resolved to an array var
380382if (\is_string ($ value ) && !$ isQuoted &&false !==strpos ($ value ,': ' )) {
@@ -521,8 +523,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
521523 }
522524break ;
523525default :
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 );
526527// Spec: Keys MUST be unique; first one wins.
527528// Parser cannot abort this mapping earlier, since lines
528529// are processed sequentially.
@@ -561,8 +562,9 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
561562 *
562563 * @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
563564 */
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 )
565566 {
567+ $ isQuotedString =false ;
566568$ scalar =trim ($ scalar );
567569$ scalarLower =strtolower ($ scalar );
568570
@@ -597,7 +599,14 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
597599case '! ' ===$ scalar [0 ]:
598600switch (true ) {
599601case 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 ;
601610case 0 ===strpos ($ scalar ,'! ' ):
602611return substr ($ scalar ,2 );
603612case 0 ===strpos ($ scalar ,'!php/object ' ):