Skip to content

Commit

Permalink
[Console] Improved checks for InputArgument and InputOption construct…
Browse files Browse the repository at this point in the history
…or's $mode parameter.

Check that $mode in InputArgument::__construct() is not below 1 to actually look if any of the flags are set.
Check that $mode in InputOption::__construct() is not below 1 to actually look if any of the flags are set.
Check for the correct parameter type, as in InputOption (integer).
InputArgumentTest: Added test for negative integer $mode parameter input in constructor.
InputOptionTest: Added test for negative integer $mode parameter input in constructor.
  • Loading branch information
ktomk committed Aug 31, 2011
1 parent c8d6c60 commit e991c59
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Input/InputArgument.php
Expand Up @@ -45,7 +45,7 @@ public function __construct($name, $mode = null, $description = '', $default = n
{
if (null === $mode) {
$mode = self::OPTIONAL;
} else if (is_string($mode) || $mode > 7) {
} else if (!is_int($mode) || $mode > 7 || $mode < 1) {
throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Input/InputOption.php
Expand Up @@ -62,7 +62,7 @@ public function __construct($name, $shortcut = null, $mode = null, $description

if (null === $mode) {
$mode = self::VALUE_NONE;
} else if (!is_int($mode) || $mode > 15) {
} else if (!is_int($mode) || $mode > 15 || $mode < 1) {
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
}

Expand Down
Expand Up @@ -40,6 +40,13 @@ public function testConstructor()
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
$this->assertEquals('Argument mode "ANOTHER_ONE" is not valid.', $e->getMessage());
}
try {
$argument = new InputArgument('foo', -1);
$this->fail('__construct() throws an Exception if the mode is not valid');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
$this->assertEquals('Argument mode "-1" is not valid.', $e->getMessage());
}
}

public function testIsArray()
Expand Down
Expand Up @@ -69,6 +69,13 @@ public function testConstructor()
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
$this->assertEquals('Option mode "ANOTHER_ONE" is not valid.', $e->getMessage());
}
try {
$option = new InputOption('foo', 'f', -1);
$this->fail('__construct() throws an Exception if the mode is not valid');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
$this->assertEquals('Option mode "-1" is not valid.', $e->getMessage());
}
}

public function testIsArray()
Expand Down

0 comments on commit e991c59

Please sign in to comment.