10000 bug #26875 [Console] Don't go past exact matches when autocompleting … · symfony/symfony@1067468 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1067468

Browse files
committed
bug #26875 [Console] Don't go past exact matches when autocompleting (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] Don't go past exact matches when autocompleting | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21789 | License | MIT | Doc PR | - Commits ------- adba79a [Console] Don't go past exact matches when autocompleting
2 parents 0f9c45e + adba79a commit 1067468

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
284284

285285
foreach ($autocomplete as $value) {
286286
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
287-
if (0 === strpos($value, $ret) && $i !== strlen($value)) {
287+
if (0 === strpos($value, $ret)) {
288288
$matches[$numMatches++] = $value;
289289
}
290290
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,30 @@ public function testAskWithAutocompleteWithNonSequentialKeys()
160160
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
161161
}
162162

163+
public function testAskWithAutocompleteWithExactMatch()
164+
{
165+
if (!$this->hasSttyAvailable()) {
166+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
167+
}
168+
169+
$inputStream = $this->getInputStream("b\n");
170+
171+
$possibleChoices = array(
172+
'a' => 'berlin',
173+
'b' => 'copenhagen',
174+
'c' => 'amsterdam',
175+
);
176+
177+
$dialog = new QuestionHelper();
178+
$dialog->setInputStream($inputStream);
179+
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
180+
181+
$question = new ChoiceQuestion('Please select a city', $possibleChoices);
182+
$question->setMaxAttempts(1);
183+
184+
$this->assertSame('b', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
185+
}
186+
163187
public function testAutocompleteWithTrailingBackslash()
164188
{
165189
if (!$this->hasSttyAvailable()) {

0 commit comments

Comments
 (0)
0