@@ -23,7 +23,6 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
23
23
const char * index_string , size_t index_string_len ,
24
24
const char * num_prefix , size_t num_prefix_len ,
25
25
const zend_string * key_prefix ,
26
- const char * key_suffix , size_t key_suffix_len ,
27
26
const zend_string * arg_sep )
28
27
{
29
28
if (form_str -> s ) {
@@ -49,8 +48,8 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
49
48
}
50
49
smart_str_append_long (form_str , index_int );
51
50
}
52
- if (key_suffix ) {
53
- smart_str_appendl (form_str , key_suffix , key_suffix_len );
51
+ if (key_prefix ) {
52
+ smart_str_appendl (form_str , "%5D" , strlen ( "%5D" ) );
54
53
}
55
54
smart_str_appendc (form_str , '=' );
56
55
@@ -97,7 +96,6 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
97
96
PHPAPI void php_url_encode_hash_ex (HashTable * ht , smart_str * formstr ,
98
97
const char * num_prefix , size_t num_prefix_len ,
99
98
const zend_string * key_prefix ,
100
- const char * key_suffix , size_t key_suffix_len ,
101
99
zval * type , const zend_string * arg_sep , int enc_type )
102
100
{
103
101
zend_string * key = NULL ;
@@ -164,15 +162,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
164
162
}
165
163
166
164
if (key_prefix ) {
167
- /* zend_string_concat4() */
168
- size_t len = ZSTR_LEN (key_prefix ) + ZSTR_LEN (encoded_key ) + key_suffix_len + strlen ("%5B" );
169
- new_prefix = zend_string_alloc (len , 0 );
170
-
171
- memcpy (ZSTR_VAL (new_prefix ), ZSTR_VAL (key_prefix ), ZSTR_LEN (key_prefix ));
172
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ), ZSTR_VAL (encoded_key ), ZSTR_LEN (encoded_key ));
173
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + ZSTR_LEN (encoded_key ), key_suffix , key_suffix_len );
174
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + ZSTR_LEN (encoded_key ) + key_suffix_len , "%5B" , strlen ("%5B" ));
175
- ZSTR_VAL (new_prefix )[len ] = '\0' ;
165
+ new_prefix = zend_string_concat3 (ZSTR_VAL (key_prefix ), ZSTR_LEN (key_prefix ), ZSTR_VAL (encoded_key ), ZSTR_LEN (encoded_key ), "%5D%5B" , strlen ("%5D%5B" ));
176
166
} else {
177
167
new_prefix = zend_string_concat2 (ZSTR_VAL (encoded_key ), ZSTR_LEN (encoded_key ), "%5B" , strlen ("%5B" ));
178
168
}
@@ -184,26 +174,17 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
184
174
index_int_as_str_len = spprintf (& index_int_as_str , 0 , ZEND_LONG_FMT , idx );
185
175
186
176
if (key_prefix && num_prefix ) {
187
- /* zend_string_concat5 () */
188
- size_t len = ZSTR_LEN (key_prefix ) + num_prefix_len + index_int_as_str_len + key_suffix_len + strlen ("%5B" );
177
+ /* zend_string_concat4 () */
178
+ size_t len = ZSTR_LEN (key_prefix ) + num_prefix_len + index_int_as_str_len + strlen ("%5D %5B" );
189
179
new_prefix = zend_string_alloc (len , 0 );
190
180
191
181
memcpy (ZSTR_VAL (new_prefix ), ZSTR_VAL (key_prefix ), ZSTR_LEN (key_prefix ));
192
182
memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ), num_prefix , num_prefix_len );
193
183
memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + num_prefix_len , index_int_as_str , index_int_as_str_len );
194
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + num_prefix_len + index_int_as_str_len , key_suffix , key_suffix_len );
195
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + num_prefix_len + index_int_as_str_len + key_suffix_len , "%5B" , strlen ("%5B" ));
184
+ memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + num_prefix_len + index_int_as_str_len , "%5D%5B" , strlen ("%5D%5B" ));
196
185
ZSTR_VAL (new_prefix )[len ] = '\0' ;
197
186
} else if (key_prefix ) {
198
- /* zend_string_concat4() */
199
- size_t len = ZSTR_LEN (key_prefix ) + index_int_as_str_len + key_suffix_len + strlen ("%5B" );
200
- new_prefix = zend_string_alloc (len , 0 );
201
-
202
- memcpy (ZSTR_VAL (new_prefix ), ZSTR_VAL (key_prefix ), ZSTR_LEN (key_prefix ));
203
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ), index_int_as_str , index_int_as_str_len );
204
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + index_int_as_str_len , key_suffix , key_suffix_len );
205
- memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ) + index_int_as_str_len + key_suffix_len , "%5B" , strlen ("%5B" ));
206
- ZSTR_VAL (new_prefix )[len ] = '\0' ;
187
+ new_prefix = zend_string_concat3 (ZSTR_VAL (key_prefix ), ZSTR_LEN (key_prefix ), index_int_as_str , index_int_as_str_len , "%5D%5B" , strlen ("%5D%5B" ));
207
188
} else if (num_prefix ) {
208
189
new_prefix = zend_string_concat3 (num_prefix , num_prefix_len , index_int_as_str , index_int_as_str_len , "%5B" , strlen ("%5B" ));
209
190
} else {
@@ -212,7 +193,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
212
193
efree (index_int_as_str );
213
194
}
214
195
GC_TRY_PROTECT_RECURSION (ht );
215
- php_url_encode_hash_ex (HASH_OF (zdata ), formstr , NULL , 0 , new_prefix , "%5D" , 3 , (Z_TYPE_P (zdata ) == IS_OBJECT ? zdata : NULL ), arg_sep , enc_type );
196
+ php_url_encode_hash_ex (HASH_OF (zdata ), formstr , NULL , 0 , new_prefix , (Z_TYPE_P (zdata ) == IS_OBJECT ? zdata : NULL ), arg_sep , enc_type );
216
197
GC_TRY_UNPROTECT_RECURSION (ht );
217
198
zend_string_release_ex (new_prefix , false);
218
199
} else if (Z_TYPE_P (zdata ) == IS_NULL || Z_TYPE_P (zdata ) == IS_RESOURCE ) {
@@ -224,7 +205,6 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
224
205
prop_name , prop_len ,
225
206
num_prefix , num_prefix_len ,
226
207
key_prefix ,
227
- key_suffix , key_suffix_len ,
228
208
arg_sep );
229
209
}
230
210
} ZEND_HASH_FOREACH_END ();
@@ -250,7 +230,7 @@ PHP_FUNCTION(http_build_query)
250
230
Z_PARAM_LONG (enc_type )
251
231
ZEND_PARSE_PARAMETERS_END ();
252
232
253
- php_url_encode_hash_ex (HASH_OF (formdata ), & formstr , prefix , prefix_len , /* key_prefix */ NULL , NULL , 0 , (Z_TYPE_P (formdata ) == IS_OBJECT ? formdata : NULL), arg_sep , (int )enc_type );
233
+ php_url_encode_hash_ex (HASH_OF (formdata ), & formstr , prefix , prefix_len , /* key_prefix */ NULL , (Z_TYPE_P (formdata ) == IS_OBJECT ? formdata : NULL), arg_sep , (int )enc_type );
254
234
255
235
RETURN_STR (smart_str_extract (& formstr ));
256
236
}
0 commit comments