diff --git a/resources-clean.xlf b/resources-clean.xlf new file mode 100644 index 0000000000..231e8a6dd2 --- /dev/null +++ b/resources-clean.xlf @@ -0,0 +1,15 @@ + + + + + + foo + bar + + + key + + + + + diff --git a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php index beeb4a1d1e..b01ac7247a 100644 --- a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php @@ -39,6 +39,9 @@ class XliffFileLoader implements LoaderInterface $catalogue = new MessageCatalogue($locale); foreach ($xml->xpath('//xliff:trans-unit') as $translation) { + if (2 !== count($translation)) { + continue; + } $catalogue->set((string) $translation->source, (string) $translation->target, $domain); } $catalogue->addResource(new FileResource($resource)); diff --git a/tests/Symfony/Tests/Component/Translation/Dumper/XliffFileDumperTest.php b/tests/Symfony/Tests/Component/Translation/Dumper/XliffFileDumperTest.php index c1bc1117c2..4df3cb19d8 100644 --- a/tests/Symfony/Tests/Component/Translation/Dumper/XliffFileDumperTest.php +++ b/tests/Symfony/Tests/Component/Translation/Dumper/XliffFileDumperTest.php @@ -19,13 +19,13 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase public function testDump() { $catalogue = new MessageCatalogue('en'); - $catalogue->add(array('foo' => 'bar')); + $catalogue->add(array('foo' => 'bar', 'key' => '')); $tempDir = sys_get_temp_dir(); $dumper = new XliffFileDumper(); $dumperString = $dumper->dump($catalogue, array('path' => $tempDir)); - $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.xlf'), file_get_contents($tempDir.'/messages.en.xlf')); + $this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources-clean.xlf'), file_get_contents($tempDir.'/messages.en.xlf')); unlink($tempDir.'/messages.en.xlf'); } diff --git a/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php b/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php index 8aa4bd4a2d..99359db600 100644 --- a/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/Translation/Loader/XliffFileLoaderTest.php @@ -22,11 +22,19 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase $resource = __DIR__.'/../fixtures/resources.xlf'; $catalogue = $loader->load($resource, 'en', 'domain1'); - $this->assertEquals(array('foo' => 'bar'), $catalogue->all('domain1')); $this->assertEquals('en', $catalogue->getLocale()); $this->assertEquals(array(new FileResource($resource)), $catalogue->getResources()); } + public function testIncompleteResource() + { + $loader = new XliffFileLoader(); + $catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1'); + + $this->assertEquals(array('foo' => 'bar', 'key' => ''), $catalogue->all('domain1')); + $this->assertFalse($catalogue->has('extra', 'domain1')); + } + /** * @expectedException \RuntimeException */ diff --git a/tests/Symfony/Tests/Component/Translation/fixtures/resources.xlf b/tests/Symfony/Tests/Component/Translation/fixtures/resources.xlf index 699f10dcda..3f43d0b09f 100644 --- a/tests/Symfony/Tests/Component/Translation/fixtures/resources.xlf +++ b/tests/Symfony/Tests/Component/Translation/fixtures/resources.xlf @@ -6,6 +6,13 @@ foo bar + + extra + + + key + +