fis querystring offset set bug
authorMichael Wallner <mike@php.net>
Tue, 3 Mar 2015 20:57:03 +0000 (21:57 +0100)
committerMichael Wallner <mike@php.net>
Tue, 3 Mar 2015 20:57:48 +0000 (21:57 +0100)
php_http_querystring.c
tests/querystring003.phpt [new file with mode: 0644]

index 933529f628062d3a8d5e09f1b548e80490269c44..f2164fb56ab7d860bdff9510a572f2bad111c605 100644 (file)
@@ -606,11 +606,19 @@ PHP_METHOD(HttpQueryString, offsetSet)
                return;
        }
 
-       MAKE_STD_ZVAL(param);
-       array_init(param);
-       Z_ADDREF_P(value);
-       add_assoc_zval_ex(param, offset_str, offset_len + 1, value);
-       php_http_querystring_set(getThis(), param, 0 TSRMLS_CC);
+       param = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+
+       if (Z_TYPE_P(param) == IS_ARRAY && zend_symtable_exists(Z_ARRVAL_P(param), offset_str, offset_len + 1)) {
+               Z_ADDREF_P(value);
+               zend_symtable_update(Z_ARRVAL_P(param), offset_str, offset_len + 1, (void *) &value, sizeof(zval *), NULL);
+               Z_ADDREF_P(param);
+       } else {
+               MAKE_STD_ZVAL(param);
+               array_init(param);
+               Z_ADDREF_P(value);
+               add_assoc_zval_ex(param, offset_str, offset_len + 1, value);
+       }
+       php_http_querystring_set(getThis(), param, QS_MERGE TSRMLS_CC);
        zval_ptr_dtor(&param);
 }
 
diff --git a/tests/querystring003.phpt b/tests/querystring003.phpt
new file mode 100644 (file)
index 0000000..a504174
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+querystring offset set
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$qs = new http\QueryString("foo=bar&bar=baz");
+echo $qs,"\n";
+$qs["foo"] = "baz";
+echo $qs,"\n";
+?>
+===DONE===
+--EXPECT--
+Test
+foo=bar&bar=baz
+foo=baz&bar=baz
+===DONE===