Skip to content

Commit f8fe899

Browse files
Merge branch '4.3' into 4.4
* 4.3: cs fix Fix inconsistent return points. [Config] Add handling for ignored keys in ArrayNode::mergeValues. Fix inconsistent return points. [Security/Core] UserInterface::getPassword() can return null [Router] Fix TraceableUrlMatcher behaviour with trailing slash Revert "bug #33092 [DependencyInjection] Improve an exception message (fabpot)"
2 parents dfc895c + 5a79a14 commit f8fe899

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

Definition/ArrayNode.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,12 @@ protected function mergeValues($leftSide, $rightSide)
396396
}
397397

398398
if (!isset($this->children[$k])) {
399-
throw new \RuntimeException('merge() expects a normalized config array.');
399+
if (!$this->ignoreExtraKeys || $this->removeExtraKeys) {
400+
throw new \RuntimeException('merge() expects a normalized config array.');
401+
}
402+
403+
$leftSide[$k] = $v;
404+
continue;
400405
}
401406

402407
$leftSide[$k] = $this->children[$k]->merge($leftSide[$k], $v);

Definition/Dumper/XmlReferenceDumper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,7 @@ private function writeValue($value): string
296296
if (\is_array($value)) {
297297
return implode(',', $value);
298298
}
299+
300+
return '';
299301
}
300302
}

Loader/FileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,7 @@ private function doImport($resource, string $type = null, bool $ignoreErrors = f
166166
throw new LoaderLoadException($resource, $sourceResource, null, $e, $type);
167167
}
168168
}
169+
170+
return null;
169171
}
170172
}

Tests/Definition/ArrayNodeTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,66 @@ public function testSetDeprecated()
255255
restore_error_handler();
256256
$this->assertTrue($deprecationTriggered, '->finalize() should trigger if the deprecated node is set');
257257
}
258+
259+
/**
260+
* @dataProvider getDataWithIncludedExtraKeys
261+
*/
262+
public function testMergeWithoutIgnoringExtraKeys($prenormalizeds, $merged)
263+
{
264+
$this->expectException('RuntimeException');
265+
$this->expectExceptionMessage('merge() expects a normalized config array.');
266+
$node = new ArrayNode('root');
267+
$node->addChild(new ScalarNode('foo'));
268+
$node->addChild(new ScalarNode('bar'));
269+
$node->setIgnoreExtraKeys(false);
270+
271+
$r = new \ReflectionMethod($node, 'mergeValues');
272+
$r->setAccessible(true);
273+
274+
$r->invoke($node, ...$prenormalizeds);
275+
}
276+
277+
/**
278+
* @dataProvider getDataWithIncludedExtraKeys
279+
*/
280+
public function testMergeWithIgnoringAndRemovingExtraKeys($prenormalizeds, $merged)
281+
{
282+
$this->expectException('RuntimeException');
283+
$this->expectExceptionMessage('merge() expects a normalized config array.');
284+
$node = new ArrayNode('root');
285+
$node->addChild(new ScalarNode('foo'));
286+
$node->addChild(new ScalarNode('bar'));
287+
$node->setIgnoreExtraKeys(true);
288+
289+
$r = new \ReflectionMethod($node, 'mergeValues');
290+
$r->setAccessible(true);
291+
292+
$r->invoke($node, ...$prenormalizeds);
293+
}
294+
295+
/**
296+
* @dataProvider getDataWithIncludedExtraKeys
297+
*/
298+
public function testMergeWithIgnoringExtraKeys($prenormalizeds, $merged)
299+
{
300+
$node = new ArrayNode('root');
301+
$node->addChild(new ScalarNode('foo'));
302+
$node->addChild(new ScalarNode('bar'));
303+
$node->setIgnoreExtraKeys(true, false);
304+
305+
$r = new \ReflectionMethod($node, 'mergeValues');
306+
$r->setAccessible(true);
307+
308+
$this->assertEquals($merged, $r->invoke($node, ...$prenormalizeds));
309+
}
310+
311+
public function getDataWithIncludedExtraKeys()
312+
{
313+
return [
314+
[
315+
[['foo' => 'bar', 'baz' => 'not foo'], ['bar' => 'baz', 'baz' => 'foo']],
316+
['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'],
317+
],
318+
];
319+
}
258320
}

0 commit comments

Comments
 (0)