18
18
#include "php_ini.h"
19
19
#include "url.h"
20
20
21
- #define URL_DEFAULT_ARG_SEP "&"
22
-
23
21
static void php_url_encode_scalar (zval * scalar , smart_str * form_str ,
24
22
int encoding_type , zend_ulong index_int ,
25
23
const char * index_string , size_t index_string_len ,
26
24
const char * num_prefix , size_t num_prefix_len ,
27
25
const char * key_prefix , size_t key_prefix_len ,
28
26
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 )
30
28
{
31
29
if (form_str -> s ) {
32
- smart_str_appendl (form_str , arg_sep , arg_sep_len );
30
+ smart_str_append (form_str , arg_sep );
33
31
}
34
32
/* Simple key=value */
35
33
if (key_prefix ) {
@@ -100,12 +98,12 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
100
98
const char * num_prefix , size_t num_prefix_len ,
101
99
const char * key_prefix , size_t key_prefix_len ,
102
100
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 )
104
102
{
105
103
zend_string * key = NULL ;
106
104
char * newprefix , * p ;
107
105
const char * prop_name ;
108
- size_t arg_sep_len , newprefix_len , prop_len ;
106
+ size_t newprefix_len , prop_len ;
109
107
zend_ulong idx ;
110
108
zval * zdata = NULL ;
111
109
ZEND_ASSERT (ht );
@@ -116,12 +114,11 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
116
114
}
117
115
118
116
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 ( '&' ) ;
122
120
}
123
121
}
124
- arg_sep_len = strlen (arg_sep );
125
122
126
123
ZEND_HASH_FOREACH_KEY_VAL (ht , idx , key , zdata ) {
127
124
bool is_dynamic = 1 ;
@@ -232,26 +229,28 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
232
229
num_prefix , num_prefix_len ,
233
230
key_prefix , key_prefix_len ,
234
231
key_suffix , key_suffix_len ,
235
- arg_sep , arg_sep_len );
232
+ arg_sep );
236
233
}
237
234
} ZEND_HASH_FOREACH_END ();
238
235
}
239
236
/* }}} */
240
237
238
+ /* If there is a prefix we need to close the key with an encoded ] ("%5D") */
241
239
/* {{{ Generates a form-encoded query string from an associative array or object. */
242
240
PHP_FUNCTION (http_build_query )
243
241
{
244
242
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 ;
247
246
smart_str formstr = {0 };
248
247
zend_long enc_type = PHP_QUERY_RFC1738 ;
249
248
250
249
ZEND_PARSE_PARAMETERS_START (1 , 4 )
251
250
Z_PARAM_ARRAY_OR_OBJECT (formdata )
252
251
Z_PARAM_OPTIONAL
253
252
Z_PARAM_STRING (prefix , prefix_len )
254
- Z_PARAM_STRING_OR_NULL (arg_sep , arg_sep_len )
253
+ Z_PARAM_STR (arg_sep )
255
254
Z_PARAM_LONG (enc_type )
256
255
ZEND_PARSE_PARAMETERS_END ();
257
256
0 commit comments