mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
- MFH: Fix handling of not existing long CLI options
This commit is contained in:
parent
76329a99f0
commit
d95939d566
2 changed files with 36 additions and 1 deletions
|
@ -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] == '-')) {
|
if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
|
||||||
/* '--' indicates end of args if not followed by a known long option name */
|
/* '--' indicates end of args if not followed by a known long option name */
|
||||||
|
if (argv[*optind][2] == '\0') {
|
||||||
|
(*optind)++;
|
||||||
|
return(EOF);
|
||||||
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
opts_idx++;
|
opts_idx++;
|
||||||
if (opts[opts_idx].opt_char == '-') {
|
if (opts[opts_idx].opt_char == '-') {
|
||||||
(*optind)++;
|
(*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)) {
|
} else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
30
sapi/cli/tests/015.phpt
Normal file
30
sapi/cli/tests/015.phpt
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue