Home » Console » Console_Getopt » Bug #10055
Not failing properly on short options missing required values
Details
| Submitted | 2007-02-08 17:43 UTC |
|---|---|
| From | jjohnston at mailwise dot com |
| Assigned | cellog |
| Status | Closed |
| Package | Console_Getopt |
| PHP Version | 4.4.4 |
| OS | SuSE 9.2 |
| Roadmaps | (Not assigned) |
Comments
[2007-02-08 17:43 UTC] jjohnston at mailwise dot com
Description:
------------
Depending on the order that command line options are passed, it is possible to 'bypass' a required value for a short option which erroneously assigns another option as the value to the previous option.
Test script:
---------------
<?php
// filename test.php
require_once 'Console/Getopt.php';
$options = new Console_Getopt();
$ret = $options->getopt($options->readPHPArgv(), 'i:r::l', array('file=','test=='));
if(PEAR::isError($ret))
{
die($ret->getMessage()."\n");
}
else
{
var_dump($ret);
}
?>
Correct results
$ php test.php -l -i
Incorrect results
$ php test.php -i -l
Expected result:
----------------
$ php test.php -l -i # Behaves correctly
$ php test.php -i -l
Console_Getopt: option requires an argument -- i
Because -i is missing its value and -l is a different option.
Actual result:
--------------
# Incorrect behavior
$ php test.php -i -l
array(2) {
[0]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(1) "i"
[1]=>
string(2) "-l"
}
}
[1]=>
array(0) {
}
}
# Correct behavior
$ php test.php -l -i
Console_Getopt: option requires an argument -- i