Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Translation] Fix handling of null messages in ArrayLoader #50315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Symfony/Component/Translation/Loader/ArrayLoader.php
Expand Up @@ -46,9 +46,11 @@ private function flatten(array $messages): array
foreach ($messages as $key => $value) {
if (\is_array($value)) {
foreach ($this->flatten($value) as $k => $v) {
$result[$key.'.'.$k] = $v;
if (null !== $v) {
$result[$key.'.'.$k] = $v;
}
}
} else {
} elseif (null !== $value) {
$result[$key] = $value;
}
}
Expand Down
Expand Up @@ -30,6 +30,15 @@ public function testLoad()
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
}

public function testLoadNonStringMessages()
{
$loader = new YamlFileLoader();
$resource = __DIR__.'/../fixtures/non-string.yml';
$catalogue = $loader->load($resource, 'en', 'domain1');

$this->assertSame(['root.foo2' => '', 'root.bar' => 'bar'], $catalogue->all('domain1'));
}

public function testLoadDoesNothingIfEmpty()
{
$loader = new YamlFileLoader();
Expand Down
@@ -0,0 +1,4 @@
root:
foo1:
foo2: ''
bar: 'bar'