Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix Bug #10557 Not failing properly on LONG options missing required …

…values (similar to 10055)

git-svn-id: http://svn.php.net/repository/pear/packages/Console_Getopt/trunk@234093 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 49bcfdfe5349d2219569168c8a130a48043a9981 1 parent be76eb7
Greg Beaver authored
Showing with 25 additions and 0 deletions.
  1. +3 −0  Console/Getopt.php
  2. +22 −0 Console/tests/bug10557.phpt
View
3  Console/Getopt.php
@@ -244,6 +244,9 @@ function _parseLongOption($arg, $long_options, &$opts, &$args)
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
}
+ if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
+ return PEAR::raiseError("Console_Getopt: option requires an argument --$opt");
+ }
}
} else if ($opt_arg) {
return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
View
22 Console/tests/bug10557.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Console_Getopt
+--SKIPIF--
+--FILE--
+<?php
+$_SERVER['argv'] =
+$argv = array('hi', '-fjjohnston@mail.com', '--to', '--mailpack', '--debug');
+require_once 'Console/Getopt.php';
+$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'f:t:',
+array('from=','to=','mailpack=','direction=','verbose','debug'));
+if(PEAR::isError($ret))
+{
+ echo $ret->getMessage()."\n";
+ echo 'FATAL';
+ exit;
+}
+
+print_r($ret);
+?>
+--EXPECT--
+Console_Getopt: option requires an argument --to
+FATAL
Please sign in to comment.
Something went wrong with that request. Please try again.