Skip to content

Commit 22f5a73

Browse files
committed
[Translation][MoFileLoader] fixed load empty translation.
1 parent a68f09e commit 22f5a73

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/Symfony/Component/Translation/Loader/MoFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ private function parse($resource)
137137
$length = $this->readLong($stream, $isBigEndian);
138138
$offset = $this->readLong($stream, $isBigEndian);
139139

140+
if ($length < 1) {
141+
continue;
142+
}
143+
140144
fseek($stream, $offset);
141145
$translated = fread($stream, $length);
142146

src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,15 @@ public function testLoadInvalidResource()
5757
$resource = __DIR__.'/../fixtures/empty.mo';
5858
$loader->load($resource, 'en', 'domain1');
5959
}
60+
61+
public function testLoadEmptyTranslation()
62+
{
63+
$loader = new MoFileLoader();
64+
$resource = __DIR__.'/../fixtures/empty-translation.mo';
65+
$catalogue = $loader->load($resource, 'en', 'message');
66+
67+
$this->assertEquals(array(), $catalogue->all('message'));
68+
$this->assertEquals('en', $catalogue->getLocale());
69+
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
70+
}
6071
}
Binary file not shown.

0 commit comments

Comments
 (0)