diff vendor/symfony/console/Helper/QuestionHelper.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
line wrap: on
line diff
--- a/vendor/symfony/console/Helper/QuestionHelper.php	Thu Feb 28 13:21:36 2019 +0000
+++ b/vendor/symfony/console/Helper/QuestionHelper.php	Thu May 09 15:33:08 2019 +0100
@@ -49,7 +49,13 @@
         if (!$input->isInteractive()) {
             $default = $question->getDefault();
 
-            if (null !== $default && $question instanceof ChoiceQuestion) {
+            if (null === $default) {
+                return $default;
+            }
+
+            if ($validator = $question->getValidator()) {
+                return \call_user_func($question->getValidator(), $default);
+            } elseif ($question instanceof ChoiceQuestion) {
                 $choices = $question->getChoices();
 
                 if (!$question->isMultiselect()) {
@@ -166,7 +172,7 @@
             if (false === $ret) {
                 $ret = fgets($inputStream, 4096);
                 if (false === $ret) {
-                    throw new RuntimeException('Aborted');
+                    throw new RuntimeException('Aborted.');
                 }
                 $ret = trim($ret);
             }
@@ -252,8 +258,11 @@
         while (!feof($inputStream)) {
             $c = fread($inputStream, 1);
 
-            // Backspace Character
-            if ("\177" === $c) {
+            // as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
+            if (false === $c || ('' === $ret && '' === $c && null === $question->getDefault())) {
+                shell_exec(sprintf('stty %s', $sttyMode));
+                throw new RuntimeException('Aborted.');
+            } elseif ("\177" === $c) { // Backspace Character
                 if (0 === $numMatches && 0 !== $i) {
                     --$i;
                     // Move cursor backwards
@@ -306,6 +315,10 @@
 
                 continue;
             } else {
+                if ("\x80" <= $c) {
+                    $c .= fread($inputStream, ["\xC0" => 1, "\xD0" => 1, "\xE0" => 2, "\xF0" => 3][$c & "\xF0"]);
+                }
+
                 $output->write($c);
                 $ret .= $c;
                 ++$i;
@@ -380,7 +393,7 @@
             shell_exec(sprintf('stty %s', $sttyMode));
 
             if (false === $value) {
-                throw new RuntimeException('Aborted');
+                throw new RuntimeException('Aborted.');
             }
 
             $value = trim($value);