@@ -106,7 +106,7 @@ public static function parse($value, $flags = 0, $references = array())
106
106
++$ i ;
107
107
break ;
108
108
default :
109
- $ result = self ::parseScalar ($ value , $ flags , null , $ i , true , $ references );
109
+ $ result = self ::parseScalar ($ value , $ flags , null , $ i , null === $ tag , $ references );
110
110
}
111
111
112
112
if (null !== $ tag ) {
@@ -413,7 +413,7 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
413
413
break ;
414
414
default :
415
415
$ isQuoted = in_array ($ sequence [$ i ], array ('" ' , "' " ));
416
- $ value = self ::parseScalar ($ sequence , $ flags , array (', ' , '] ' ), $ i , true , $ references );
416
+ $ value = self ::parseScalar ($ sequence , $ flags , array (', ' , '] ' ), $ i , null === $ tag , $ references );
417
417
418
418
// the value can be an array if a reference has been resolved to an array var
419
419
if (is_string ($ value ) && !$ isQuoted && false !== strpos ($ value , ': ' )) {
@@ -492,6 +492,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
492
492
continue ;
493
493
}
494
494
495
+ $ tag = self ::parseTag ($ mapping , $ i , $ flags );
495
496
$ duplicate = false ;
496
497
switch ($ mapping [$ i ]) {
497
498
case '[ ' :
@@ -517,7 +518,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
517
518
}
518
519
break ;
519
520
default :
520
- $ value = self ::parseScalar ($ mapping , $ flags , array (', ' , '} ' ), $ i , true , $ references );
521
+ $ value = self ::parseScalar ($ mapping , $ flags , array (', ' , '} ' ), $ i , null === $ tag , $ references );
521
522
// Spec: Keys MUST be unique; first one wins.
522
523
// Parser cannot abort this mapping earlier, since lines
523
524
// are processed sequentially.
@@ -529,7 +530,11 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
529
530
}
530
531
531
532
if (!$ duplicate ) {
532
- $ output [$ key ] = $ value ;
533
+ if (null !== $ tag ) {
534
+ $ output [$ key ] = new TaggedValue ($ value , $ tag );
535
+ } else {
536
+ $ output [$ key ] = $ value ;
537
+ }
533
538
}
534
539
++$ i ;
535
540
@@ -633,7 +638,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
633
638
@trigger_error (sprintf ('Using the unquoted scalar value "%s" is deprecated since version 3.3 and will be considered as a tagged value in 4.0. You must quote it. ' , $ scalar ), E_USER_DEPRECATED );
634
639
}
635
640
636
- // Optimise for returning strings.
641
+ // Optimize for returning strings.
637
642
case $ scalar [0 ] === '+ ' || $ scalar [0 ] === '- ' || $ scalar [0 ] === '. ' || is_numeric ($ scalar [0 ]):
638
643
switch (true ) {
639
644
case preg_match ('{^[+-]?[0-9][0-9_]*$} ' , $ scalar ):
@@ -687,10 +692,11 @@ private static function evaluateScalar($scalar, $flags, $references = array())
687
692
/**
688
693
* @param string $value
689
694
* @param int &$i
695
+ * @param int $flags
690
696
*
691
- * @return null|array| string
697
+ * @return null|string
692
698
*/
693
- private static function parseTag ($ value , &$ i = 0 , $ flags )
699
+ private static function parseTag ($ value , &$ i , $ flags )
694
700
{
695
701
if ('! ' !== $ value [$ i ]) {
696
702
return ;
@@ -703,12 +709,12 @@ private static function parseTag($value, &$i = 0, $flags)
703
709
$ nextOffset += strspn ($ value , ' ' , $ nextOffset );
704
710
705
711
// Is followed by a scalar
706
- if (!isset ($ value [$ nextOffset ]) || !in_array ($ value [$ nextOffset ], array ('[ ' , '{ ' ))) {
712
+ if (!isset ($ value [$ nextOffset ]) || !in_array ($ value [$ nextOffset ], array ('[ ' , '{ ' ), true )) {
707
713
// Manage scalars in {@link self::evaluateScalar()}
708
714
return ;
709
715
}
710
716
711
- if ($ flags & Yaml::PARSE_CUSTOM_TAGS ) {
717
+ if (Yaml::PARSE_CUSTOM_TAGS & $ flags ) {
712
718
$ i = $ nextOffset ;
713
719
714
720
return $ tag ;
0 commit comments