1818#include "php_ini.h"
1919#include "url.h"
2020
21- #define URL_DEFAULT_ARG_SEP "&"
22-
2321static void php_url_encode_scalar (zval * scalar , smart_str * form_str ,
2422 int encoding_type , zend_ulong index_int ,
2523 const char * index_string , size_t index_string_len ,
2624 const char * num_prefix , size_t num_prefix_len ,
2725 const char * key_prefix , size_t key_prefix_len ,
2826 const char * key_suffix , size_t key_suffix_len ,
29- const char * arg_sep , size_t arg_sep_len )
27+ const zend_string * arg_sep )
3028{
3129 if (form_str -> s ) {
32- smart_str_appendl (form_str , arg_sep , arg_sep_len );
30+ smart_str_append (form_str , arg_sep );
3331 }
3432 /* Simple key=value */
3533 if (key_prefix ) {
@@ -100,12 +98,12 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
10098 const char * num_prefix , size_t num_prefix_len ,
10199 const char * key_prefix , size_t key_prefix_len ,
102100 const char * key_suffix , size_t key_suffix_len ,
103- zval * type , const char * arg_sep , int enc_type )
101+ zval * type , const zend_string * arg_sep , int enc_type )
104102{
105103 zend_string * key = NULL ;
106104 char * newprefix , * p ;
107105 const char * prop_name ;
108- size_t arg_sep_len , newprefix_len , prop_len ;
106+ size_t newprefix_len , prop_len ;
109107 zend_ulong idx ;
110108 zval * zdata = NULL ;
111109 ZEND_ASSERT (ht );
@@ -116,12 +114,11 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
116114 }
117115
118116 if (!arg_sep ) {
119- arg_sep = INI_STR ("arg_separator.output" );
120- if (! arg_sep || ! strlen (arg_sep )) {
121- arg_sep = URL_DEFAULT_ARG_SEP ;
117+ arg_sep = zend_ini_str ("arg_separator.output" , strlen ( "arg_separator.output" ), false );
118+ if (ZSTR_LEN (arg_sep ) == 0 ) {
119+ arg_sep = ZSTR_CHAR ( '&' ) ;
122120 }
123121 }
124- arg_sep_len = strlen (arg_sep );
125122
126123 ZEND_HASH_FOREACH_KEY_VAL (ht , idx , key , zdata ) {
127124 bool is_dynamic = 1 ;
@@ -232,26 +229,28 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
232229 num_prefix , num_prefix_len ,
233230 key_prefix , key_prefix_len ,
234231 key_suffix , key_suffix_len ,
235- arg_sep , arg_sep_len );
232+ arg_sep );
236233 }
237234 } ZEND_HASH_FOREACH_END ();
238235}
239236/* }}} */
240237
238+ /* If there is a prefix we need to close the key with an encoded ] ("%5D") */
241239/* {{{ Generates a form-encoded query string from an associative array or object. */
242240PHP_FUNCTION (http_build_query )
243241{
244242 zval * formdata ;
245- char * prefix = NULL , * arg_sep = NULL ;
246- size_t arg_sep_len = 0 , prefix_len = 0 ;
243+ char * prefix = NULL ;
244+ size_t prefix_len = 0 ;
245+ zend_string * arg_sep = NULL ;
247246 smart_str formstr = {0 };
248247 zend_long enc_type = PHP_QUERY_RFC1738 ;
249248
250249 ZEND_PARSE_PARAMETERS_START (1 , 4 )
251250 Z_PARAM_ARRAY_OR_OBJECT (formdata )
252251 Z_PARAM_OPTIONAL
253252 Z_PARAM_STRING (prefix , prefix_len )
254- Z_PARAM_STRING_OR_NULL (arg_sep , arg_sep_len )
253+ Z_PARAM_STR (arg_sep )
255254 Z_PARAM_LONG (enc_type )
256255 ZEND_PARSE_PARAMETERS_END ();
257256
0 commit comments