Skip to content

Commit e267876

Browse files
Merge branch '3.4' into 4.0
* 3.4: (22 commits) fix merge [Translation] Fix InvalidArgumentException when using untranslated plural forms from .po files Fixed exit code with non-integer throwable code [HttpFoundation] Support 0 bit netmask in IPv6 () [DI] Impossible to set an environment variable and then an array as container parameter [Process] remove false-positive BC breaking exception on Windows Tweaking class not found autowiring error [LDAP] added missing dots at the end of some exception messages. [TwigBridge] Add missing dev requirement for workflow fixed #25440 empty lines don't count for indent detection Set `width: auto` on WebProfiler toolbar's reset. [Lock] Fix incorrect phpdoc [Process] Dont rely on putenv(), it fails on ZTS PHP [HttpKernel] detect deprecations thrown by container initialization during tests [HttpKernel] Fix logging of post-terminate errors/exceptions [DI] Add context to service-not-found exceptions thrown by service locators [Debug] Fix catching fatal errors in case of nested error handlers [VarDumper] Fixed file links leave blank pages when ide is configured Fix hidden currency element with Bootstrap 3 theme ...
2 parents 317c200 + 4c5d558 commit e267876

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

MessageSelector.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ class MessageSelector
4949
*/
5050
public function choose($message, $number, $locale)
5151
{
52-
preg_match_all('/(?:\|\||[^\|])++/', $message, $parts);
52+
$parts = array();
53+
if (preg_match('/^\|++$/', $message)) {
54+
$parts = explode('|', $message);
55+
} elseif (preg_match_all('/(?:\|\||[^\|])++/', $message, $matches)) {
56+
$parts = $matches[0];
57+
}
58+
5359
$explicitRules = array();
5460
$standardRules = array();
55-
foreach ($parts[0] as $part) {
61+
foreach ($parts as $part) {
5662
$part = trim(str_replace('||', '|', $part));
5763

5864
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/xs', $part, $matches)) {
@@ -76,7 +82,7 @@ public function choose($message, $number, $locale)
7682
if (!isset($standardRules[$position])) {
7783
// when there's exactly one rule given, and that rule is a standard
7884
// rule, use this rule
79-
if (1 === count($parts[0]) && isset($standardRules[0])) {
85+
if (1 === count($parts) && isset($standardRules[0])) {
8086
return $standardRules[0];
8187
}
8288

Tests/MessageSelectorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ public function getChooseTests()
128128
array("This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1),
129129
// esacape pipe
130130
array('This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0),
131+
// Empty plural set (2 plural forms) from a .PO file
132+
array('', '|', 1),
133+
// Empty plural set (3 plural forms) from a .PO file
134+
array('', '||', 1),
131135
);
132136
}
133137
}

0 commit comments

Comments
 (0)