8000 [Yaml] Stop replacing NULLs when merging · symfony/symfony@d967440 · GitHub
[go: up one dir, main page]

Skip to content

Commit d967440

Browse files
committed
[Yaml] Stop replacing NULLs when merging
1 parent ffe3ab1 commit d967440

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
161161
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
162162
}
163163

164-
foreach ($refValue as $key => $value) {
165-
if (!isset($data[$key])) {
166-
$data[$key] = $value;
167-
}
168-
}
164+
$data += $refValue; // array union
169165
} else {
170166
if (isset($values['value']) && $values['value'] !== '') {
171167
$value = $values['value'];
@@ -187,20 +183,12 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
187183
throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem);
188184
}
189185

190-
foreach ($parsedItem as $key => $value) {
191-
if (!isset($data[$key])) {
192-
$data[$key] = $value;
193-
}
194-
}
186+
$data += $parsedItem; // array union
195187
}
196188
} else {
197189
// If the value associated with the key is a single mapping node, each of its key/value pairs is inserted into the
198190
// current mapping, unless the key already exists in it.
199-
foreach ($parsed as $key => $value) {
200-
if (!isset($data[$key])) {
201-
$data[$key] = $value;
202-
}
203-
}
191+
$data += $parsed; // array union
204192
}
205193
}
206194
} elseif (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {

src/Symfony/Component/Yaml/Tests/Fixtures/sfMergeKey.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ yaml: |
1010
a: Steve
1111
b: Clark
1212
c: Brian
13+
e: notnull
1314
bar:
1415
a: before
1516
d: other
17+
e: ~
16< AA04 /code>18
<<: *foo
1719
b: new
1820
x: Oren
@@ -46,13 +48,13 @@ yaml: |
4648
<<: *nestedref
4749
php: |
4850
array(
49-
'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian'),
50-
'bar' => array('a' => 'before', 'd' => 'other', 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
51+
'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull'),
52+
'bar' => array('a' => 'before', 'd' => 'other', 'e' => null, 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
5153
'duplicate' => array('foo' => 'bar'),
5254
'foo2' => array('a' => 'Ballmer'),
5355
'ding' => array('fi', 'fei', 'fo', 'fam'),
54-
'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'),
55-
'head' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam'),
56+
'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'),
57+
'head' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
5658
'taz' => array('a' => 'Steve', 'w' => array('p' => 1234)),
5759
'nested' => array('a' => 'Steve', 'w' => array('p' => 12345), 'd' => 'Doug', 'z' => array('p' => 12345))
5860
)

0 commit comments

Comments
 (0)
0