Skip to content

Commit 7276abb

Browse files
onthebediluuu1994
authored andcommitted
fix(cli): clear optional getopt arg
1 parent dc807bc commit 7276abb

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

main/getopt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
5757
static char **prev_optarg = NULL;
5858

5959
php_optidx = -1;
60+
if (optarg) {
61+
*optarg = NULL;
62+
}
6063

6164
if(prev_optarg && prev_optarg != optarg) {
6265
/* reset the state */

sapi/cli/tests/bug21901.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
CLI getopt preserves empty optional long option arguments
3+
--FILE--
4+
<?php
5+
$php_escaped = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
6+
$cmd = $php_escaped . ' -n -d foo=bar --ini';
7+
echo shell_exec($cmd);
8+
?>
9+
--EXPECTF--
10+
Configuration File (php.ini) Path: "%s"
11+
Loaded Configuration File: %s
12+
Scan for additional .ini files in: %s
13+
Additional .ini files parsed: %s

0 commit comments

Comments
 (0)