@@ -23,7 +23,6 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
2323 const char * index_string , size_t index_string_len ,
2424 const char * num_prefix , size_t num_prefix_len ,
2525 const zend_string * key_prefix ,
26- const char * key_suffix , size_t key_suffix_len ,
2726 const zend_string * arg_sep )
2827{
2928 if (form_str -> s ) {
@@ -49,8 +48,8 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
4948 }
5049 smart_str_append_long (form_str , index_int );
5150 }
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" ) );
5453 }
5554 smart_str_appendc (form_str , '=' );
5655
@@ -97,7 +96,6 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
9796PHPAPI void php_url_encode_hash_ex (HashTable * ht , smart_str * formstr ,
9897 const char * num_prefix , size_t num_prefix_len ,
9998 const zend_string * key_prefix ,
100- const char * key_suffix , size_t key_suffix_len ,
10199 zval * type , const zend_string * arg_sep , int enc_type )
102100{
103101 zend_string * key = NULL ;
@@ -164,15 +162,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
164162 }
165163
166164 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" ));
176166 } else {
177167 new_prefix = zend_string_concat2 (ZSTR_VAL (encoded_key ), ZSTR_LEN (encoded_key ), "%5B" , strlen ("%5B" ));
178168 }
@@ -184,26 +174,17 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
184174 index_int_as_str_len = spprintf (& index_int_as_str , 0 , ZEND_LONG_FMT , idx );
185175
186176 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" );
189179 new_prefix = zend_string_alloc (len , 0 );
190180
191181 memcpy (ZSTR_VAL (new_prefix ), ZSTR_VAL (key_prefix ), ZSTR_LEN (key_prefix ));
192182 memcpy (ZSTR_VAL (new_prefix ) + ZSTR_LEN (key_prefix ), num_prefix , num_prefix_len );
193183 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" ));
196185 ZSTR_VAL (new_prefix )[len ] = '\0' ;
197186 } 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" ));
207188 } else if (num_prefix ) {
208189 new_prefix = zend_string_concat3 (num_prefix , num_prefix_len , index_int_as_str , index_int_as_str_len , "%5B" , strlen ("%5B" ));
209190 } else {
@@ -212,7 +193,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
212193 efree (index_int_as_str );
213194 }
214195 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 );
216197 GC_TRY_UNPROTECT_RECURSION (ht );
217198 zend_string_release_ex (new_prefix , false);
218199 } 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,
224205 prop_name , prop_len ,
225206 num_prefix , num_prefix_len ,
226207 key_prefix ,
227- key_suffix , key_suffix_len ,
228208 arg_sep );
229209 }
230210 } ZEND_HASH_FOREACH_END ();
@@ -250,7 +230,7 @@ PHP_FUNCTION(http_build_query)
250230 Z_PARAM_LONG (enc_type )
251231 ZEND_PARSE_PARAMETERS_END ();
252232
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 );
254234
255235 RETURN_STR (smart_str_extract (& formstr ));
256236}
0 commit comments