Browse Source

fix that argument with 0 as value will stop parsing args, tests added

Ceeram 14 years ago
parent
commit
828117583f

+ 1 - 1
lib/Cake/Console/ConsoleOptionParser.php

@@ -467,7 +467,7 @@ class ConsoleOptionParser {
 		}
 		$params = $args = array();
 		$this->_tokens = $argv;
-		while ($token = array_shift($this->_tokens)) {
+		while (($token = array_shift($this->_tokens)) !== null) {
 			if (substr($token, 0, 2) == '--') {
 				$params = $this->_parseLongOption($token, $params);
 			} elseif (substr($token, 0, 1) == '-') {

+ 13 - 0
lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php

@@ -351,6 +351,19 @@ class ConsoleOptionParserTest extends CakeTestCase {
 	}
 
 /**
+ * test parsing arguments with 0 value.
+ *
+ * @return void
+ */
+	public function testParseArgumentZero() {
+		$parser = new ConsoleOptionParser('test', false);
+
+		$expected = array('one', 'two', 0, 'after', 'zero');
+		$result = $parser->parse($expected);
+		$this->assertEquals($expected, $result[1], 'Arguments are not as expected');
+	}
+
+/**
  * test that when there are not enough arguments an exception is raised
  *
  * @expectedException ConsoleException