diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index 72880f6a69cc..92a4c7d0fb52 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -110,11 +110,6 @@ private function doAsk(OutputInterface $output, Question $question) $inputStream = $this->inputStream ?: \STDIN; $autocomplete = $question->getAutocompleterCallback(); - if (\function_exists('sapi_windows_cp_set')) { - // Codepage used by cmd.exe on Windows to allow special characters (éàüñ). - @sapi_windows_cp_set(1252); - } - if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) { $ret = false; if ($question->isHidden()) { @@ -514,7 +509,10 @@ private function isInteractiveInput($inputStream): bool private function readInput($inputStream, Question $question) { if (!$question->isMultiline()) { - return fgets($inputStream, 4096); + $cp = $this->setIOCodepage(); + $ret = fgets($inputStream, 4096); + + return $this->resetIOCodepage($cp, $ret); } $multiLineStreamReader = $this->cloneInputStream($inputStream); @@ -523,6 +521,7 @@ private function readInput($inputStream, Question $question) } $ret = ''; + $cp = $this->setIOCodepage(); while (false !== ($char = fgetc($multiLineStreamReader))) { if (\PHP_EOL === "{$ret}{$char}") { break; @@ -530,7 +529,37 @@ private function readInput($inputStream, Question $question) $ret .= $char; } - return $ret; + return $this->resetIOCodepage($cp, $ret); + } + + /** + * Set console I/O to the host code page. + * + * @return int Previous code page in IBM/EBCDIC format + */ + private function setIOCodepage(): int + { + if (\function_exists('sapi_windows_cp_set')) { + $cp = sapi_windows_cp_get(); + sapi_windows_cp_set(sapi_windows_cp_get('oem')); + + return $cp; + } + + return 0; + } + + /** + * Set console I/O to the specified code page and convert the user input. + */ + private function resetIOCodepage(int $cp, string $input): string + { + if (\function_exists('sapi_windows_cp_set') && 0 < $cp) { + sapi_windows_cp_set($cp); + $input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input); + } + + return $input; } /** pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy