From 864568fdc0208b3eba3638b6000b69d2386e6768 Mon Sep 17 00:00:00 2001 From: Marek Zajac Date: Tue, 11 May 2021 15:45:56 +0200 Subject: [PATCH] [Console] Fix Windows code page support --- Helper/QuestionHelper.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index a28fa4ee0..340b552aa 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -512,7 +512,7 @@ private function readInput($inputStream, Question $question) $cp = $this->setIOCodepage(); $ret = fgets($inputStream, 4096); - return false !== $ret ? $this->resetIOCodepage($cp, $ret) : false; + return $this->resetIOCodepage($cp, $ret); } $multiLineStreamReader = $this->cloneInputStream($inputStream); @@ -533,7 +533,7 @@ private function readInput($inputStream, Question $question) } /** - * Set console I/O to the host code page. + * Sets console I/O to the host code page. * * @return int Previous code page in IBM/EBCDIC format */ @@ -550,13 +550,20 @@ private function setIOCodepage(): int } /** - * Set console I/O to the specified code page and convert the user input. + * 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, string $input): string + private function resetIOCodepage(int $cp, $input) { - if (\function_exists('sapi_windows_cp_set') && 0 < $cp) { + if (0 !== $cp) { sapi_windows_cp_set($cp); - $input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input); + + if (false !== $input && '' !== $input) { + $input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input); + } } return $input;