summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schlüter <johannes@php.net>2007-03-22 21:34:58 +0000
committerJohannes Schlüter <johannes@php.net>2007-03-22 21:34:58 +0000
commit5dc2d0b0d69adfa2a4c278f2df8725d73c9d7109 (patch)
treeeb039ece663744ec32a05d23fe6bb74e30c05349
parent5506943c53112738e7d5c51619362fe1e0981564 (diff)
downloadphp-git-5dc2d0b0d69adfa2a4c278f2df8725d73c9d7109.tar.gz
- Fix handling of not existing long CLI options
-rw-r--r--sapi/cli/getopt.c7
-rw-r--r--sapi/cli/tests/015.phpt30
2 files changed, 36 insertions, 1 deletions
diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c
index 8634003dae..963c4554e1 100644
--- a/sapi/cli/getopt.c
+++ b/sapi/cli/getopt.c
@@ -79,11 +79,16 @@ int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **opta
}
if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
/* '--' indicates end of args if not followed by a known long option name */
+ if (argv[*optind][2] == '\0') {
+ (*optind)++;
+ return(EOF);
+ }
+
while (1) {
opts_idx++;
if (opts[opts_idx].opt_char == '-') {
(*optind)++;
- return(EOF);
+ return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
} else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
break;
}
diff --git a/sapi/cli/tests/015.phpt b/sapi/cli/tests/015.phpt
new file mode 100644
index 0000000000..e5c0ab0259
--- /dev/null
+++ b/sapi/cli/tests/015.phpt
@@ -0,0 +1,30 @@
+--TEST--
+CLI long options
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+
+$php = getenv('TEST_PHP_EXECUTABLE');
+
+
+echo `"$php" --version | grep built:`;
+echo `echo "<?php print_r(\\\$argv);" | "$php" -- foo bar baz`, "\n";
+echo `"$php" --version foo bar baz | grep built:`;
+echo `"$php" --notexisting foo bar baz | grep Usage:`;
+
+echo "Done\n";
+?>
+--EXPECTF--
+PHP %d.%d.%d%s(cli) (built: %s)
+Array
+(
+ [0] => -
+ [1] => foo
+ [2] => bar
+ [3] => baz
+)
+
+PHP %d.%d.%d%s(cli) (built: %s)
+Usage: php [options] [-f] <file> [--] [args...]
+Done