@@ -320,7 +320,11 @@ private static function dumpArray($value, $flags)
320
320
*/
321
321
public static function parseScalar ($ scalar , $ flags = 0 , $ delimiters = null , &$ i = 0 , $ evaluate = true , $ references = [], $ legacyOmittedKeySupport = false )
322
322
{
323
- if (\in_array ($ scalar [$ i ], ['" ' , "' " ])) {
323
+ if ('' === $ scalar = (string ) $ scalar ) {
324
+ return '' ;
325
+ }
326
+
327
+ if (isset ($ scalar [$ i ]) && \in_array ($ scalar [$ i ], ['" ' , "' " ])) {
324
328
// quoted scalar
325
329
$ output = self ::parseQuotedScalar ($ scalar , $ i );
326
330
@@ -513,7 +517,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = []
513
517
}
514
518
515
519
if (!$ isKeyQuoted ) {
516
- $ evaluatedKey = self ::evaluateScalar ($ key , $ flags , $ references );
520
+ $ evaluatedKey = self ::evaluateScalar ($ key , $ flags , $ references, true );
517
521
518
522
if ('' !== $ key && $ evaluatedKey !== $ key && !\is_string ($ evaluatedKey ) && !\is_int ($ evaluatedKey )) {
519
523
@trigger_error (self ::getDeprecationMessage ('Implicit casting of incompatible mapping keys to strings is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead. ' ), E_USER_DEPRECATED );
@@ -611,12 +615,13 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = []
611
615
* @param string $scalar
612
616
* @param int $flags
613
617
* @param array $references
618
+ * @param bool $isMappingKey
614
619
*
615
620
* @return mixed The evaluated YAML string
616
621
*
617
622
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
618
623
*/
619
- private static function evaluateScalar ($ scalar , $ flags , $ references = [])
624
+ private static function evaluateScalar ($ scalar , $ flags , $ references = [], $ isMappingKey = false )
620
625
{
621
626
$ scalar = trim ($ scalar );
622
627
$ scalarLower = strtolower ($ scalar );
@@ -712,6 +717,10 @@ private static function evaluateScalar($scalar, $flags, $references = [])
712
717
return null ;
713
718
case 0 === strpos ($ scalar , '!php/const ' ):
714
719
if (self ::$ constantSupport ) {
720
+ if ($ isMappingKey ) {
721
+ throw new ParseException ('The !php/const tag is not supported in a mapping key. ' , self ::$ parsedLineNumber + 1 , $ scalar , self ::$ parsedFilename );
722
+ }
723
+
715
724
$ i = 0 ;
716
725
if (\defined ($ const = self ::parseScalar (substr ($ scalar , 11 ), 0 , null , $ i , false ))) {
717
726
return \constant ($ const );
0 commit comments