Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / translation / MessageSelector.php
index bdbb0f965fff0da82c75c9b5a385f28f135df07e..c6134191bce084acaea696f2037a6018bd0e0c72 100644 (file)
@@ -11,6 +11,8 @@
 
 namespace Symfony\Component\Translation;
 
+use Symfony\Component\Translation\Exception\InvalidArgumentException;
+
 /**
  * MessageSelector.
  *
@@ -43,15 +45,15 @@ class MessageSelector
      *
      * @return string
      *
-     * @throws \InvalidArgumentException
+     * @throws InvalidArgumentException
      */
     public function choose($message, $number, $locale)
     {
-        $parts = explode('|', $message);
+        preg_match_all('/(?:\|\||[^\|])++/', $message, $parts);
         $explicitRules = array();
         $standardRules = array();
-        foreach ($parts as $part) {
-            $part = trim($part);
+        foreach ($parts[0] as $part) {
+            $part = trim(str_replace('||', '|', $part));
 
             if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/xs', $part, $matches)) {
                 $explicitRules[$matches['interval']] = $matches['message'];
@@ -74,11 +76,11 @@ class MessageSelector
         if (!isset($standardRules[$position])) {
             // when there's exactly one rule given, and that rule is a standard
             // rule, use this rule
-            if (1 === count($parts) && isset($standardRules[0])) {
+            if (1 === count($parts[0]) && isset($standardRules[0])) {
                 return $standardRules[0];
             }
 
-            throw new \InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale, $number));
+            throw new InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale, $number));
         }
 
         return $standardRules[$position];