Skip to content

Commit 044b585

Browse files
orkannicolas-grekas
authored andcommitted
[Console] Fix Windows code page support
1 parent f3f8027 commit 044b585

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ private function readInput($inputStream, Question $question)
512512
$cp = $this->setIOCodepage();
513513
$ret = fgets($inputStream, 4096);
514514

515-
return false !== $ret ? $this->resetIOCodepage($cp, $ret) : false;
515+
return $this->resetIOCodepage($cp, $ret);
516516
}
517517

518518
$multiLineStreamReader = $this->cloneInputStream($inputStream);
@@ -533,7 +533,7 @@ private function readInput($inputStream, Question $question)
533533
}
534534

535535
/**
536-
* Set console I/O to the host code page.
536+
* Sets console I/O to the host code page.
537537
*
538538
* @return int Previous code page in IBM/EBCDIC format
539539
*/
@@ -550,13 +550,20 @@ private function setIOCodepage(): int
550550
}
551551

552552
/**
553-
* Set console I/O to the specified code page and convert the user input.
553+
* Sets console I/O to the specified code page and converts the user input.
554+
*
555+
* @param string|false $input
556+
*
557+
* @return string|false
554558
*/
555-
private function resetIOCodepage(int $cp, string $input): string
559+
private function resetIOCodepage(int $cp, $input)
556560
{
557-
if (\function_exists('sapi_windows_cp_set') && 0 < $cp) {
561+
if (0 !== $cp) {
558562
sapi_windows_cp_set($cp);
559-
$input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input);
563+
564+
if (false !== $input && '' !== $input) {
565+
$input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input);
566+
}
560567
}
561568

562569
return $input;

0 commit comments

Comments
 (0)
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