Skip to content
Permalink
Browse files

Fix issues with using 0 as an option for a shell command.

Fixes #2079
  • Loading branch information...
markstory committed Oct 10, 2011
1 parent 5d3fdfc commit bc6de1841747bf1140c9dfa5af19da9e8aa6ce45
Showing with 15 additions and 6 deletions.
  1. +1 −2 cake/console/cake.php
  2. +2 −4 cake/console/libs/shell.php
  3. +12 −0 cake/tests/cases/console/libs/shell.test.php
@@ -450,7 +450,7 @@ function getInput($prompt, $options = null, $default = null) {
}
$result = trim($result);
if ($default != null && empty($result)) {
if ($default !== null && ($result === '' || $result === null)) {
return $default;
}
return $result;
@@ -471,7 +471,6 @@ function stdout($string, $newline = true) {
return fwrite($this->stdout, $string);
}
}
/**
* Outputs to the stderr filehandle.
*
@@ -347,13 +347,11 @@ function in($prompt, $options = null, $default = null) {
}
}
if (is_array($options)) {
while ($in == '' || ($in && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
while ($in === '' || ($in !== '' && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
$in = $this->Dispatch->getInput($prompt, $options, $default);
}
}
if ($in) {
return $in;
}
return $in;
}
/**
@@ -208,6 +208,18 @@ function testIn() {
$result = $this->Shell->in('Just a test?', 'y', 'y');
$this->assertEqual($result, 'y');
$this->Shell->Dispatch->setReturnValueAt(5, 'getInput', 'y');
$this->Shell->Dispatch->expectAt(5, 'getInput', array('Just a test?', array(0, 1, 2), 0));
$result = $this->Shell->in('Just a test?', array(0, 1, 2), 0);
$this->assertEqual($result, 0);
}
/**
* Test in() when not interactive
*
* @return void
*/
function testInNonInteractive() {
$this->Shell->interactive = false;
$result = $this->Shell->in('Just a test?', 'y/n', 'n');

0 comments on commit bc6de18

Please sign in to comment.
You can’t perform that action at this time.