Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit136b72f

Browse files
committed
handles multi-byte characters in autocomplete
1 parent5ad1f37 commit136b72f

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
308308

309309
continue;
310310
}else {
311+
for ($b =0;$b <4; ++$b) {
312+
if (false ===mb_ord($c)) {
313+
$c .=fread($inputStream,1);
314+
}
315+
}
316+
311317
$output->write($c);
312318
$ret .=$c;
313319
++$i;

‎src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,43 @@ public function testAskWithAutocompleteWithExactMatch()
237237
$this->assertSame('b',$dialog->ask($this->createStreamableInputInterfaceMock($inputStream),$this->createOutputInterface(),$question));
238238
}
239239

240+
publicfunctiongetInputs()
241+
{
242+
return [
243+
['$'],// 1 byte character
244+
['¢'],// 2 bytes character
245+
[''],// 3 bytes character
246+
['𐍈'],// 4 bytes character
247+
];
248+
}
249+
250+
/**
251+
* @dataProvider getInputs
252+
*/
253+
publicfunctiontestAskWithAutocompleteWithMultiByteCharacter($character)
254+
{
255+
if (!$this->hasSttyAvailable()) {
256+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
257+
}
258+
259+
$inputStream =$this->getInputStream("$character\n");
260+
261+
$possibleChoices = [
262+
'$' =>'1 byte character',
263+
'¢' =>'2 bytes character',
264+
'' =>'3 bytes character',
265+
'𐍈' =>'4 bytes character',
266+
];
267+
268+
$dialog =newQuestionHelper();
269+
$dialog->setHelperSet(newHelperSet([newFormatterHelper()]));
270+
271+
$question =newChoiceQuestion('Please select a character',$possibleChoices);
272+
$question->setMaxAttempts(1);
273+
274+
$this->assertSame($character,$dialog->ask($this->createStreamableInputInterfaceMock($inputStream),$this->createOutputInterface(),$question));
275+
}
276+
240277
publicfunctiontestAutocompleteWithTrailingBackslash()
241278
{
242279
if (!$this->hasSttyAvailable()) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp