- fix retval of http_parse_params
authorMichael Wallner <mike@php.net>
Sat, 20 May 2006 13:18:38 +0000 (13:18 +0000)
committerMichael Wallner <mike@php.net>
Sat, 20 May 2006 13:18:38 +0000 (13:18 +0000)
- add test

http_functions.c
tests/parse_params_001.phpt [new file with mode: 0644]

index ceac1a1eee4bbb3d9797e0c0df87149138fd4196..0dfb68bcf9747e9554d7392a21a8814f0d839087 100644 (file)
@@ -1097,16 +1097,21 @@ PHP_FUNCTION(http_parse_params)
 {
        char *param;
        int param_len;
+       zval *params;
        
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &param, &param_len)) {
                RETURN_FALSE;
        }
        
-       object_init(return_value);
-       if (SUCCESS != http_parse_params(param, HASH_OF(return_value))) {
-               zval_dtor(return_value);
+       params = ecalloc(1, sizeof(zval));
+       array_init(params);
+       if (SUCCESS != http_parse_params(param, Z_ARRVAL_P(params))) {
+               zval_dtor(params);
+               FREE_ZVAL(params);
                RETURN_FALSE;
        }
+       object_init(return_value);
+       add_property_zval(return_value, "params", params);
 }
 /* }}} */
 
diff --git a/tests/parse_params_001.phpt b/tests/parse_params_001.phpt
new file mode 100644 (file)
index 0000000..1dc452e
--- /dev/null
@@ -0,0 +1,74 @@
+--TEST--
+http_parse_params
+--SKIPIF--
+<?php
+include 'skip.inc';
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+var_dump(http_parse_params('text/html; charset=iso-8859-1'));
+var_dump(http_parse_params('text/html; charset="iso-8859-1"'));
+var_dump(http_parse_params('attachment; filename="gol;got,a.ext"'));
+var_dump(http_parse_params('public, must-revalidate, max-age=0'));
+var_dump(http_parse_params('a')->params[0]);
+var_dump(http_parse_params('a=b')->params[0]);
+echo "Done\n";
+--EXPECTF--
+%sTEST
+object(stdClass)#%d (%d) {
+  ["params"]=>
+  array(2) {
+    [0]=>
+    string(9) "text/html"
+    [1]=>
+    array(1) {
+      ["charset"]=>
+      string(10) "iso-8859-1"
+    }
+  }
+}
+object(stdClass)#%d (%d) {
+  ["params"]=>
+  array(2) {
+    [0]=>
+    string(9) "text/html"
+    [1]=>
+    array(1) {
+      ["charset"]=>
+      string(10) "iso-8859-1"
+    }
+  }
+}
+object(stdClass)#%d (%d) {
+  ["params"]=>
+  array(2) {
+    [0]=>
+    string(10) "attachment"
+    [1]=>
+    array(1) {
+      ["filename"]=>
+      string(13) "gol;got,a.ext"
+    }
+  }
+}
+object(stdClass)#%d (%d) {
+  ["params"]=>
+  array(3) {
+    [0]=>
+    string(6) "public"
+    [1]=>
+    string(15) "must-revalidate"
+    [2]=>
+    array(1) {
+      ["max-age"]=>
+      string(1) "0"
+    }
+  }
+}
+string(1) "a"
+array(1) {
+  ["a"]=>
+  string(1) "b"
+}
+Done