summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/standard/basic_functions.c8
-rw-r--r--ext/standard/tests/general_functions/getopt_002.phpt42
-rw-r--r--ext/standard/tests/general_functions/getopt_003.phpt57
3 files changed, 104 insertions, 3 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 1688d44642..93057d9e09 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -4506,7 +4506,8 @@ static int parse_opts(char * opts, opt_struct ** result)
int i, count = 0;
for (i = 0; i < strlen(opts); i++) {
- if ((opts[i] >= 65 && opts[i] <= 90) ||
+ if ((opts[i] >= 48 && opts[i] <= 57) ||
+ (opts[i] >= 65 && opts[i] <= 90) ||
(opts[i] >= 97 && opts[i] <= 122)
) {
count++;
@@ -4516,8 +4517,9 @@ static int parse_opts(char * opts, opt_struct ** result)
paras = safe_emalloc(sizeof(opt_struct), count, 0);
memset(paras, 0, sizeof(opt_struct) * count);
*result = paras;
- while ( (*opts >= 65 && *opts <= 90) ||
- (*opts >= 97 && *opts <= 122)
+ while ( (*opts >= 48 && *opts <= 57) || /* 0 - 9 */
+ (*opts >= 65 && *opts <= 90) || /* A - Z */
+ (*opts >= 97 && *opts <= 122) /* a - z */
) {
paras->opt_char = *opts;
paras->need_param = (*(++opts) == ':') ? 1 : 0;
diff --git a/ext/standard/tests/general_functions/getopt_002.phpt b/ext/standard/tests/general_functions/getopt_002.phpt
new file mode 100644
index 0000000000..3912ec87c7
--- /dev/null
+++ b/ext/standard/tests/general_functions/getopt_002.phpt
@@ -0,0 +1,42 @@
+--TEST--
+getopt#002
+--ARGS--
+-vvv -a value -1111 -2 -v
+--INI--
+register_argc_argv=On
+variables_order=GPS
+--FILE--
+<?php
+ var_dump(getopt("2a:vcd1"));
+?>
+--EXPECT--
+array(4) {
+ ["v"]=>
+ array(4) {
+ [0]=>
+ bool(false)
+ [1]=>
+ bool(false)
+ [2]=>
+ bool(false)
+ [3]=>
+ bool(false)
+ }
+ ["a"]=>
+ string(5) "value"
+ [1]=>
+ array(4) {
+ [0]=>
+ bool(false)
+ [1]=>
+ bool(false)
+ [2]=>
+ bool(false)
+ [3]=>
+ bool(false)
+ }
+ [2]=>
+ bool(false)
+}
+
+
diff --git a/ext/standard/tests/general_functions/getopt_003.phpt b/ext/standard/tests/general_functions/getopt_003.phpt
new file mode 100644
index 0000000000..fbb39b0e55
--- /dev/null
+++ b/ext/standard/tests/general_functions/getopt_003.phpt
@@ -0,0 +1,57 @@
+--TEST--
+getopt#003
+--ARGS--
+-vvv --v -a value --another value -1111 -2 --12 --0 --0 --1 -v
+--INI--
+register_argc_argv=On
+variables_order=GPS
+--FILE--
+<?php
+ var_dump(getopt("2a:vcd1", array("another:", 12, 0, 1, "v")));
+?>
+--EXPECT--
+array(7) {
+ ["v"]=>
+ array(5) {
+ [0]=>
+ bool(false)
+ [1]=>
+ bool(false)
+ [2]=>
+ bool(false)
+ [3]=>
+ bool(false)
+ [4]=>
+ bool(false)
+ }
+ ["a"]=>
+ string(5) "value"
+ ["another"]=>
+ string(5) "value"
+ [1]=>
+ array(5) {
+ [0]=>
+ bool(false)
+ [1]=>
+ bool(false)
+ [2]=>
+ bool(false)
+ [3]=>
+ bool(false)
+ [4]=>
+ bool(false)
+ }
+ [2]=>
+ bool(false)
+ [12]=>
+ bool(false)
+ [0]=>
+ array(2) {
+ [0]=>
+ bool(false)
+ [1]=>
+ bool(false)
+ }
+}
+
+