]> granicus.if.org Git - php/commitdiff
- Allow numeric options
authorHannes Magnusson <bjori@php.net>
Thu, 15 Nov 2007 13:11:48 +0000 (13:11 +0000)
committerHannes Magnusson <bjori@php.net>
Thu, 15 Nov 2007 13:11:48 +0000 (13:11 +0000)
- Add tests

ext/standard/basic_functions.c
ext/standard/tests/general_functions/getopt_002.phpt [new file with mode: 0644]
ext/standard/tests/general_functions/getopt_003.phpt [new file with mode: 0644]

index 597a9557ed019a3830d941b8ff0f1339099919e6..49bc6113d810533831261d39835b177077165ed7 100644 (file)
@@ -4470,7 +4470,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++;
@@ -4480,8 +4481,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 (file)
index 0000000..3912ec8
--- /dev/null
@@ -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 (file)
index 0000000..fbb39b0
--- /dev/null
@@ -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)
+  }
+}
+
+