@@ -351,7 +351,8 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
351
351
continue ;
352
352
}
353
353
354
- $ tag = self ::parseTag ($ sequence , $ i , $ flags );
354
+ $ isQuoted = false ;
355
+ $ tag = self ::parseTag ($ sequence , $ i , $ flags , '] ' );
355
356
switch ($ sequence [$ i ]) {
356
357
case '[ ' :
357
358
// nested sequence
@@ -380,6 +381,10 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
380
381
}
381
382
382
383
if (null !== $ tag && '' !== $ tag ) {
384
+ if ('' === $ value && !$ isQuoted ) {
385
+ $ value = null ;
386
+ }
387
+
383
388
$ value = new TaggedValue ($ tag , $ value );
384
389
}
385
390
@@ -456,7 +461,8 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
456
461
continue ;
457
462
}
458
463
459
- $ tag = self ::parseTag ($ mapping , $ i , $ flags );
464
+ $ isValueQuoted = false ;
465
+ $ tag = self ::parseTag ($ mapping , $ i , $ flags , '} ' );
460
466
switch ($ mapping [$ i ]) {
461
467
case '[ ' :
462
468
// nested sequence
@@ -479,6 +485,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
479
485
}
480
486
break ;
481
487
default :
488
+ $ isValueQuoted = in_array ($ mapping [$ i ], array ('" ' , "' " ));
482
489
$ value = self ::parseScalar ($ mapping , $ flags , array (', ' , '} ' ), $ i , null === $ tag , $ references );
483
490
// Spec: Keys MUST be unique; first one wins.
484
491
// Parser cannot abort this mapping earlier, since lines
@@ -490,6 +497,10 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
490
497
}
491
498
492
499
if (null !== $ tag && '' !== $ tag ) {
500
+ if ('' === $ value && !$ isValueQuoted ) {
501
+ $ value = null ;
502
+ }
503
+
493
504
$ output [$ key ] = new TaggedValue ($ tag , $ value );
494
505
} else {
495
506
$ output [$ key ] = $ value ;
@@ -635,16 +646,17 @@ private static function evaluateScalar($scalar, $flags, $references = array())
635
646
* @param string $value
636
647
* @param int &$i
637
648
* @param int $flags
649
+ * @param string $stopOn
638
650
*
639
651
* @return null|string
640
652
*/
641
- private static function parseTag ($ value , &$ i , $ flags )
653
+ private static function parseTag ($ value , &$ i , $ flags, $ stopOn = '' )
642
654
{
643
655
if ('! ' !== $ value [$ i ]) {
644
656
return ;
645
657
}
646
658
647
- $ tagLength = strcspn ($ value , " \t\n" , $ i + 1 );
659
+ $ tagLength = strcspn ($ value , " \t\n" . $ stopOn , $ i + 1 );
648
660
$ tag = substr ($ value , $ i + 1 , $ tagLength );
649
661
650
662
$ nextOffset = $ i + $ tagLength + 1 ;
0 commit comments