[BUGFIX] Return NULL instead of empty string in Localization::translate()
authordkd-egerer Sascha Egerer <sascha.egerer@dkd.de>
Fri, 13 Apr 2012 09:38:47 +0000 (11:38 +0200)
committerOliver Hader <oliver@typo3.org>
Fri, 20 Jul 2012 16:31:50 +0000 (18:31 +0200)
Localization::translate() returns an empty string instead of NULL
if no translation string is found but arguments are given

Change-Id: Id21ca9bc59a59d6115dc70decf2294497d871a81
Fixes: #34874
Related: #34877
Releases: 6.0, 4.7, 1.4, 1.3

typo3/sysext/extbase/Classes/Utility/Localization.php
typo3/sysext/extbase/Tests/Unit/Utility/LocalizationTest.php

index 737ccc3..799dc6f 100644 (file)
@@ -119,7 +119,7 @@ class Tx_Extbase_Utility_Localization {
                                }
                        }
                }
-               if (is_array($arguments)) {
+               if (is_array($arguments) && $value !== NULL) {
                        return vsprintf($value, $arguments);
                } else {
                        return $value;
index 2754cd9..63c5901 100644 (file)
@@ -66,5 +66,23 @@ class Tx_Extbase_Tests_Unit_Utility_LocalizationTest extends Tx_Extbase_Tests_Un
                ));
                $this->assertEquals($expected, $actual);
        }
+
+       /**
+        * @test
+        */
+       public function translateForEmptyStringKeyReturnsNull() {
+               $this->assertNull(
+                       Tx_Extbase_Utility_Localization::translate('', 'extbase')
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function translateForEmptyStringKeyWithArgumentsReturnsNull() {
+               $this->assertNull(
+                       Tx_Extbase_Utility_Localization::translate('', 'extbase', array('argument'))
+               );
+       }
 }
 ?>
\ No newline at end of file