Skip to content

Commit

Permalink
Fix bug where backspacing to an empty string and using the arrow keys…
Browse files Browse the repository at this point in the history
… would fail. Added test to prevent in future
  • Loading branch information
lmcd authored and stloyd committed Jan 8, 2013
1 parent cf99804 commit a843508
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Helper/DialogHelper.php
Expand Up @@ -115,12 +115,12 @@ public function ask(OutputInterface $output, $question, $default = null, array $
$ofs = -1;
$matches = $autocomplete;
$numMatches = count($matches);
} else {
$numMatches = 0;
}

// Pop the last character off the end of our string
$ret = substr($ret, 0, $i);

$numMatches = 0;
} elseif ("\033" === $c) { // Did we read an escape sequence?
$c .= fread($inputStream, 2);

Expand Down
6 changes: 4 additions & 2 deletions Tests/Helper/DialogHelperTest.php
Expand Up @@ -66,9 +66,10 @@ public function testAskWithAutocomplete()
// Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
// <NEWLINE>
// <UP ARROW><UP ARROW><NEWLINE>
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB><NEWLINE>
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
// <DOWN ARROW><NEWLINE>
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\n");
// S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\n");

$dialog = new DialogHelper();
$dialog->setInputStream($inputStream);
Expand All @@ -81,6 +82,7 @@ public function testAskWithAutocomplete()
$this->assertEquals('SecurityBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
$this->assertEquals('FooBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
$this->assertEquals('AsseticBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
}

public function testAskHiddenResponse()
Expand Down

0 comments on commit a843508

Please sign in to comment.