From 5809712a2b48e5b07599de7e7a8416d33f72b9ed Mon Sep 17 00:00:00 2001 From: Marek Zajac Date: Thu, 13 May 2021 07:53:50 +0200 Subject: [PATCH 1/2] [Console] Fix Windows code page support --- Helper/QuestionHelper.php | 44 ++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index f1a3c4b5d..2f582d458 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -108,11 +108,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()) { @@ -127,7 +122,9 @@ private function doAsk(OutputInterface $output, Question $question) } if (false === $ret) { + $cp = $this->setIOCodepage(); $ret = fgets($inputStream, 4096); + $ret = $this->resetIOCodepage($cp, $ret); if (false === $ret) { throw new MissingInputException('Aborted.'); } @@ -503,4 +500,41 @@ private function isInteractiveInput($inputStream): bool return self::$stdinIsInteractive = 1 !== $status; } + + /** + * Sets 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; + } + + /** + * Sets console I/O to the specified code page and converts the user input. + * + * @param string|false $input + * + * @return string|false + */ + private function resetIOCodepage(int $cp, $input) + { + if (0 !== $cp) { + sapi_windows_cp_set($cp); + + if (false !== $input && '' !== $input) { + $input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input); + } + } + + return $input; + } } From a62acecdf5b50e314a4f305cd01b5282126f3095 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 26 May 2021 13:20:16 +0200 Subject: [PATCH 2/2] Fix markdown --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3e2fc605e..c89b4a1a2 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ interfaces. Resources --------- - * [Documentation](https://symfony.com/doc/current/components/console.html) - * [Contributing](https://symfony.com/doc/current/contributing/index.html) - * [Report issues](https://github.com/symfony/symfony/issues) and - [send Pull Requests](https://github.com/symfony/symfony/pulls) - in the [main Symfony repository](https://github.com/symfony/symfony) + * [Documentation](https://symfony.com/doc/current/components/console.html) + * [Contributing](https://symfony.com/doc/current/contributing/index.html) + * [Report issues](https://github.com/symfony/symfony/issues) and + [send Pull Requests](https://github.com/symfony/symfony/pulls) + in the [main Symfony repository](https://github.com/symfony/symfony) Credits -------