Skip to content

Commit

Permalink
Don't throw an exception on '' message strings.
Browse files Browse the repository at this point in the history
Instead return '' instead of an exception when the message string is ''.

Refs #8932
  • Loading branch information
markstory committed Sep 10, 2016
1 parent add105f commit 13f006f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/I18n/Formatter/IcuFormatter.php
Expand Up @@ -86,6 +86,9 @@ public function format($locale, $message, array $vars)
*/
protected function _formatMessage($locale, $message, $vars)
{
if ($message === '') {
return $message;
}
// Using procedural style as it showed twice as fast as
// its counterpart in PHP 5.5
$result = MessageFormatter::formatMessage($locale, $message, $vars);
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/I18n/Formatter/IcuFormatterTest.php
Expand Up @@ -22,6 +22,16 @@
*/
class IcuFormatterTest extends TestCase
{
/**
* Tests that empty values can be used as formatting strings
*
* @return void
*/
public function testFormatEmptyValues()
{
$formatter = new IcuFormatter();
$this->assertEquals('', $formatter->format('en_US', '', []));
}

/**
* Tests that variables are interpolated correctly
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/I18n/I18nTest.php
Expand Up @@ -345,6 +345,29 @@ public function testBasicContextFunction()
);
}

/**
* Tests the __x() function with no msgstr
*
* @return void
*/
public function testBasicContextFunctionNoString()
{
I18n::translator('default', 'en_US', function () {
$package = new Package('default');
$package->setMessages([
'letter' => [
'_context' => [
'character' => '',
]
]
]);

return $package;
});

$this->assertEquals('', __x('character', 'letter'));
}

/**
* Tests the __xn() function
*
Expand Down

0 comments on commit 13f006f

Please sign in to comment.