-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Fixes question input encoding on Windows #37385
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
Conversation
Can you please add a test for this? It should run on windows only. |
Is there a group in PHPUnit to run only on Windows (like |
If the function exists only on windows, it should be enough yes. symfony/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php Lines 418 to 420 in 3308b25
|
Ok thank you! I'm writing it. |
It's difficult to test it because the stream used for QuestionHelper tests is the PHP memory |
This solution does not work 😞 |
Can you try the following test locally? Without your patch at first, in order to make sure it breaks under your setup.
|
No more results... I think PHPUnit simulate and standard input but does not take all behaviors of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me as is.
Oh, note that codepage 65001 is UTF-8, it would be even better. Can you give it a try? |
Only 1252 and 850 work (and 437 of course). I think the better code page is 1252 because it provides a better characters support. |
Does the function return false is your case with 65001? |
No it returns true but replaces |
Thanks for fixing this bug @YaFou. |
I'm facing this issue again in 5.2.x-dev, i'm using windows 10, before i ask question, all utf8 chars are wrong. |
Thank you for your feedback @lpj145. Can you provide a screenshot from your terminal? Are you on Windows? |
With this change, the value returned by the helper on Windows is a binary string. Take this example command: <?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
class TestCommand extends Command
{
protected static $defaultName = 'app:test';
protected function execute(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
$question = new Question('What? ');
dump($helper->ask($input, $output, $question));
return Command::SUCCESS;
}
} This is the output for the input martínez:
If I remove the call to
This issue was initially reported here, but after some tests I think the issue is caused by this change. I tested it using three terminal emulators: CMD, PowerPhell and Git Bash: |
I have a similar issue on Windows 10, Symfony 5.2.6, Hungarian OS environment and chars like áíűőüöúóé. After first ansfer output gets wrong charset even if I don't use any special characters in questions or answers. And it's not just the output, all the inner encoding settings become strange, e.g. Works: $command = $this->getApplication()->find('generate');
$generateArguments = [
'project' => 'local',
];
return $command->run(new ArrayInput($generateArguments), $output); Error: $helper = $this->getHelper('question');
$projectQuestion = new Question("Projekt: </> \n", 'local');
$project = $helper->ask($input, $output, $projectQuestion);
$command = $this->getApplication()->find('generate');
$generateArguments = [
'project' => $project,
];
return $command->run(new ArrayInput($generateArguments), $output); |
This PR was submitted for the 5.x branch but it was squashed and merged into the 5.2 branch instead. Discussion ---------- [Console] Fix Windows code page support | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37385, Fix #35842, Fix #36324, Fix #37495, Fix #37278 | License | MIT Corrects previous fixes that dealt with the mojibake problem on Windows where an OEM code page was applied to an input string and then messed with PHP.internal_encoding setting used by the script. This caused strings with different encodings to be displayed on the console output. Commits ------- be68682 [Console] Fix Windows code page support
This PR was merged into the 4.4 branch. Discussion ---------- [Console] Fix Windows code page support | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37385, Fix #35842, Fix #36324, Fix #37495, Fix #37278 | License | MIT Corrects mojibake problem on Windows where an OEM code page was applied to an input string and then messed with PHP.internal_encoding setting used by the script. This caused strings with different encodings to be displayed on the console output. Commits ------- 4145278 [Console] Fix Windows code page support
To ask a question to a user, the QuestionHelper use
fgets
. However, special characters are not supported on Windows with this function (like accents:é
,à
,ö
). The solution is to set a special encoding withsapi_windows_cp_get
.Thanks to @bnjmnfnk for the solution 😉