Skip to content

Commit bd0eaef

Browse files
committed
bug symfony#13953 [Translation][MoFileLoader] fixed load empty translation. (aitboudad)
This PR was merged into the 2.3 branch. Discussion ---------- [Translation][MoFileLoader] fixed load empty translation. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | symfony#13547 | Tests pass? | yes | License | MIT see https://www.gnu.org/software/gettext/manual/html_node/MO-Files.html ![selection_003](https://cloud.githubusercontent.com/assets/1753742/6690874/fcf04ef6-ccba-11e4-83a4-4f50188709c5.png) Commits ------- 22f5a73 [Translation][MoFileLoader] fixed load empty translation.
2 parents d2007bf + 22f5a73 commit bd0eaef

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)