@@ -181,7 +181,7 @@ private function doParse($value, $exceptionOnInvalidType = false, $objectSupport
181
181
$ key = (string ) $ key ;
182
182
}
183
183
184
- if ('<< ' === $ key ) {
184
+ if ('<< ' === $ key && (! isset ( $ values [ ' value ' ]) || ! self :: preg_match ( ' #^&(?P<ref>[^ ]+)#u ' , $ values [ ' value ' ], $ refMatches )) ) {
185
185
$ mergeNode = true ;
186
186
$ allowOverwrite = true ;
187
187
if (isset ($ values ['value ' ]) && 0 === strpos ($ values ['value ' ], '* ' )) {
@@ -226,14 +226,14 @@ private function doParse($value, $exceptionOnInvalidType = false, $objectSupport
226
226
$ data += $ parsed ; // array union
227
227
}
228
228
}
229
- } elseif (isset ($ values ['value ' ]) && self ::preg_match ('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u ' , $ values ['value ' ], $ matches )) {
229
+ } elseif (' << ' !== $ key && isset ($ values ['value ' ]) && self ::preg_match ('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u ' , $ values ['value ' ], $ matches )) {
230
230
$ isRef = $ matches ['ref ' ];
231
231
$ values ['value ' ] = $ matches ['value ' ];
232
232
}
233
233
234
234
if ($ mergeNode ) {
235
235
// Merge keys
236
- } elseif (!isset ($ values ['value ' ]) || '' == trim ($ values ['value ' ], ' ' ) || 0 === strpos (ltrim ($ values ['value ' ], ' ' ), '# ' )) {
236
+ } elseif (!isset ($ values ['value ' ]) || '' == trim ($ values ['value ' ], ' ' ) || 0 === strpos (ltrim ($ values ['value ' ], ' ' ), '# ' ) || ' << ' === $ key ) {
237
237
// hash
238
238
// if next line is less indented or equal, then it means that the current value is null
239
239
if (!$ this ->isNextLineIndented () && !$ this ->isNextLineUnIndentedCollection ()) {
@@ -244,9 +244,13 @@ private function doParse($value, $exceptionOnInvalidType = false, $objectSupport
244
244
}
245
245
} else {
246
246
$ value = $ this ->parseBlock ($ this ->getRealCurrentLineNb () + 1 , $ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport , $ objectForMap );
247
- // Spec: Keys MUST be unique; first one wins.
248
- // But overwriting is allowed when a merge node is used in current block.
249
- if ($ allowOverwrite || !isset ($ data [$ key ])) {
247
+
248
+ if ('<< ' === $ key ) {
249
+ $ this ->refs [$ refMatches ['ref ' ]] = $ value ;
250
+ $ data += $ value ;
251
+ } elseif ($ allowOverwrite || !isset ($ data [$ key ])) {
252
+ // Spec: Keys MUST be unique; first one wins.
253
+ // But overwriting is allowed when a merge node is used in current block.
250
254
$ data [$ key ] = $ value ;
251
255
}
252
256
}
0 commit comments