Pull merge.
[yaffs-website] / vendor / symfony / console / Question / ChoiceQuestion.php
index 522a81bb146d55750c103c1e7f2c3df5e35bcc74..0a45d74932522920dee37a4897d83e883343d2ad 100644 (file)
@@ -26,14 +26,16 @@ class ChoiceQuestion extends Question
     private $errorMessage = 'Value "%s" is invalid';
 
     /**
-     * Constructor.
-     *
      * @param string $question The question to ask to the user
      * @param array  $choices  The list of available choices
      * @param mixed  $default  The default answer to return
      */
     public function __construct($question, array $choices, $default = null)
     {
+        if (!$choices) {
+            throw new \LogicException('Choice question must have at least 1 choice available.');
+        }
+
         parent::__construct($question, $default);
 
         $this->choices = $choices;
@@ -137,7 +139,7 @@ class ChoiceQuestion extends Question
 
             if ($multiselect) {
                 // Check for a separated comma values
-                if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
+                if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
                     throw new InvalidArgumentException(sprintf($errorMessage, $selected));
                 }
                 $selectedChoices = explode(',', $selectedChoices);
@@ -154,7 +156,7 @@ class ChoiceQuestion extends Question
                     }
                 }
 
-                if (count($results) > 1) {
+                if (\count($results) > 1) {
                     throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results)));
                 }