From 614f707afdcca47e4cc6cdd5eb8926c363be909f Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Sat, 20 May 2006 13:18:38 +0000 Subject: [PATCH] - fix retval of http_parse_params - add test --- http_functions.c | 11 ++++-- tests/parse_params_001.phpt | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 tests/parse_params_001.phpt diff --git a/http_functions.c b/http_functions.c index ceac1a1..0dfb68b 100644 --- a/http_functions.c +++ b/http_functions.c @@ -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", ¶m, ¶m_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 index 0000000..1dc452e --- /dev/null +++ b/tests/parse_params_001.phpt @@ -0,0 +1,74 @@ +--TEST-- +http_parse_params +--SKIPIF-- + +--FILE-- +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 -- 2.30.2