Skip to content

Commit 62fdf81

Browse files
Merge branch '5.2' into 5.x
* 5.2: (23 commits) [Console] Fix Windows code page support [SecurityBundle] Allow ips parameter in access_control accept comma-separated string [Form] Add TranslatableMessage support to choice_label option of ChoiceType Remove code that deals with legacy behavior of PHP_Incomplete_Class [Config][DependencyInjection] Uniformize trailing slash handling [PropertyInfo] Make ReflectionExtractor correctly extract nullability [PropertyInfo] fix attribute namespace with recursive traits [PhpUnitBridge] Fix tests with `@doesNotPerformAssertions` annotations Check redis extension version [Security] Update Russian translations [Notifier] Fix return SentMessage then Messenger not used [VarExporter] Add support of PHP enumerations [Security] Added missing Japanese translations [Security] Added missing Polish translations [Security] Add missing Italian translations #41051 [Security] Missing translations pt_BR getProtocolVersion may return null Fix return type on isAllowedProperty method Make FailoverTransport always pick the first transport [TwigBridge] Fix HTML for translatable custom-file label in Bootstrap 4 theme ...
2 parents 959bfea + abf150a commit 62fdf81

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

Helper/QuestionHelper.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ private function doAsk(OutputInterface $output, Question $question)
110110
$inputStream = $this->inputStream ?: \STDIN;
111111
$autocomplete = $question->getAutocompleterCallback();
112112

113-
if (\function_exists('sapi_windows_cp_set')) {
114-
// Codepage used by cmd.exe on Windows to allow special characters (éàüñ).
115-
@sapi_windows_cp_set(1252);
116-
}
117-
118113
if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
119114
$ret = false;
120115
if ($question->isHidden()) {
@@ -514,7 +509,10 @@ private function isInteractiveInput($inputStream): bool
514509
private function readInput($inputStream, Question $question)
515510
{
516511
if (!$question->isMultiline()) {
517-
return fgets($inputStream, 4096);
512+
$cp = $this->setIOCodepage();
513+
$ret = fgets($inputStream, 4096);
514+
515+
return $this->resetIOCodepage($cp, $ret);
518516
}
519517

520518
$multiLineStreamReader = $this->cloneInputStream($inputStream);
@@ -523,14 +521,45 @@ private function readInput($inputStream, Question $question)
523521
}
524522

525523
$ret = '';
524+
$cp = $this->setIOCodepage();
526525
while (false !== ($char = fgetc($multiLineStreamReader))) {
527526
if (\PHP_EOL === "{$ret}{$char}") {
528527
break;
529528
}
530529
$ret .= $char;
531530
}
532531

533-
return $ret;
532+
return $this->resetIOCodepage($cp, $ret);
533+
}
534+
535+
/**
536+
* Set console I/O to the host code page.
537+
*
538+
* @return int Previous code page in IBM/EBCDIC format
539+
*/
540+
private function setIOCodepage(): int
541+
{
542+
if (\function_exists('sapi_windows_cp_set')) {
543+
$cp = sapi_windows_cp_get();
544+
sapi_windows_cp_set(sapi_windows_cp_get('oem'));
545+
546+
return $cp;
547+
}
548+
549+
return 0;
550+
}
551+
552+
/**
553+
* Set console I/O to the specified code page and convert the user input.
554+
*/
555+
private function resetIOCodepage(int $cp, string $input): string
556+
{
557+
if (\function_exists('sapi_windows_cp_set') && 0 < $cp) {
558+
sapi_windows_cp_set($cp);
559+
$input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input);
560+
}
561+
562+
return $input;
534563
}
535564

536565
/**

0 commit comments

Comments
 (0)