Skip to content

Commit db9964d

Browse files
committed
fix(cli): clear optional getopt arg
1 parent 61e62a4 commit db9964d

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

main/getopt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ 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+
*optarg = NULL;
6061

6162
if(prev_optarg && prev_optarg != optarg) {
6263
/* reset the state */

sapi/cli/tests/bug21901.phpt

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

0 commit comments

Comments
 (0)