[Console] fixed corrupt error output for unknown multibyte short option

This commit is contained in:
downace 2018-09-08 01:12:13 +09:00 committed by Robin Chalas
parent d32d7685c2
commit 0f861568aa
2 changed files with 7 additions and 1 deletions

View File

@ -121,7 +121,8 @@ class ArgvInput extends Input
$len = \strlen($name);
for ($i = 0; $i < $len; ++$i) {
if (!$this->definition->hasShortcut($name[$i])) {
throw new RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
$encoding = mb_detect_encoding($name, null, true);
throw new RuntimeException(sprintf('The "-%s" option does not exist.', false === $encoding ? $name[$i] : mb_substr($name, $i, 1, $encoding)));
}
$option = $this->definition->getOptionForShortcut($name[$i]);

View File

@ -228,6 +228,11 @@ class ArgvInputTest extends TestCase
new InputDefinition(array(new InputArgument('number'))),
'The "-1" option does not exist.',
),
array(
array('cli.php', '-fЩ'),
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
'The "-Щ" option does not exist.',
),
);
}