diff options
-rw-r--r-- | it.class | 2 | ||||
-rwxr-xr-x | test/getopt.t | 3 |
2 files changed, 4 insertions, 1 deletions
@@ -902,7 +902,7 @@ static function getopt($usage, $p = array()) foreach(explode("\n", trim($usage)) as $usageline) { $shortoptname = $shortoptarg = $longoptname = $longoptarg = ""; - foreach (explode(',', $usageline) as $optdesc) + foreach (explode(',', $usageline, 2) as $optdesc) { $optdesc = trim($optdesc); if ($matches = (array)it::match('^--(\w[\w-]*)(=[A-Z])?', $optdesc)) diff --git a/test/getopt.t b/test/getopt.t index 77e52ae..380d0fd 100755 --- a/test/getopt.t +++ b/test/getopt.t @@ -9,6 +9,7 @@ $GLOBALS['usage'] = "Usage: doesnotexist.php [OPTIONS] POSITIONAL [VARARGS] -a,--argument=ARG the arg argument -d,--default=ARG an argument with default [defäult] -0,--zero testworthy shortarg + -c,--comma option with comma and, -minus in the description "; function getopt_ok($argv, $exp, $name) @@ -26,6 +27,7 @@ foreach (["" => "blah gnaber", " (umlaute)" => "pre üäpost"] as $variant => $t getopt_ok([$testarg, "--argument=$testarg"], $exp, "Long version with equal" . $variant); } +getopt_ok(['posargs', '-c'], ['args' => [], 'positional' => 'posargs', 'comma' => true, 'default' => 'defäult'], "comma and minus in description doesn't break shortopt"); $exp = ['args' => [], 'positional' => 'posarg', 'zero' => true, 'default' => 'defäult']; getopt_ok(['posarg', '-0'], $exp, 'short argument -0 without value'); getopt_ok(['posarg', '--zero'], $exp, 'long argument --zero without value'); @@ -33,6 +35,7 @@ getopt_ok(['posarg', '-0', 'vararg'], ['args' => ['vararg']] + $exp, "additional getopt_ok(['posarg', '--zero', 'vararg'], ['args' => ['vararg']] + $exp, "additional value after long argument --zero"); fclose(STDERR); +getopt_ok(['posargs', '-m'], false, "comma and minus in description doesn't break shortopt 2"); getopt_ok(['posarg', '--unknown'], false, "Unknown long named argument fails"); getopt_ok(['posarg', '-u'], false, "Unknown short named argument fails"); getopt_ok([], false, "Missing positional argument fails"); |