Skip to content

[Console] Fix Windows code page support #41174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
*/
Expand All @@ -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;
Expand Down