File tree 2 files changed +33
-0
lines changed
src/Symfony/Component/Yaml
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -332,6 +332,11 @@ private function doParse($value, $flags)
332
332
$ value = $ this ->parseBlock ($ this ->getRealCurrentLineNb () + 1 , $ this ->getNextEmbedBlock (), $ flags );
333
333
if ('<< ' === $ key ) {
334
334
$ this ->refs [$ refMatches ['ref ' ]] = $ value ;
335
+
336
+ if (Yaml::PARSE_OBJECT_FOR_MAP & $ flags && $ value instanceof \stdClass) {
337
+ $ value = (array ) $ value ;
338
+ }
339
+
335
340
$ data += $ value ;
336
341
} elseif ($ allowOverwrite || !isset ($ data [$ key ])) {
337
342
// Spec: Keys MUST be unique; first one wins.
Original file line number Diff line number Diff line change @@ -1941,6 +1941,34 @@ public function testParseReferencesOnMergeKeys()
1941
1941
1942
1942
$ this ->assertSame ($ expected , $ this ->parser ->parse ($ yaml ));
1943
1943
}
1944
+
1945
+ public function testParseReferencesOnMergeKeysWithMappingsParsedAsObjects ()
1946
+ {
1947
+ $ yaml = <<<YAML
1948
+ mergekeyrefdef:
1949
+ a: foo
1950
+ <<: &quux
1951
+ b: bar
1952
+ c: baz
1953
+ mergekeyderef:
1954
+ d: quux
1955
+ <<: *quux
1956
+ YAML ;
1957
+ $ expected = (object ) array (
1958
+ 'mergekeyrefdef ' => (object ) array (
1959
+ 'a ' => 'foo ' ,
1960
+ 'b ' => 'bar ' ,
1961
+ 'c ' => 'baz ' ,
1962
+ ),
1963
+ 'mergekeyderef ' => (object ) array (
1964
+ 'd ' => 'quux ' ,
1965
+ 'b ' => 'bar ' ,
1966
+ 'c ' => 'baz ' ,
1967
+ ),
1968
+ );
1969
+
1970
+ $ this ->assertEquals ($ expected , $ this ->parser ->parse ($ yaml , Yaml::PARSE_OBJECT_FOR_MAP ));
1971
+ }
4C43
div>
1944
1972
}
1945
1973
1946
1974
class B
You can’t perform that action at this time.
0 commit comments