@@ -172,14 +172,17 @@ zend_result php_uri_parser_rfc3986_userinfo_write(struct uri_internal_t *interna
172
172
result = uriSetUserInfoMmA (uriparser_uri , Z_STRVAL_P (value ), Z_STRVAL_P (value ) + Z_STRLEN_P (value ), mm );
173
173
}
174
174
175
- if (result != URI_SUCCESS ) {
176
- zend_throw_exception (uri_invalid_uri_exception_ce , "The specified userinfo is malformed" , 0 );
177
- return FAILURE ;
175
+ switch (result ) {
176
+ case URI_SUCCESS :
177
+ reset_normalized_uri_after_writing (internal_uri );
178
+ return SUCCESS ;
179
+ case URI_ERROR_SETUSERINFO_HOST_NOT_SET :
180
+ zend_throw_exception (uri_invalid_uri_exception_ce , "Cannot set a userinfo without having a host" , 0 );
181
+ return FAILURE ;
182
+ default :
183
+ zend_throw_exception (uri_invalid_uri_exception_ce , "The specified userinfo is malformed" , 0 );
184
+ return FAILURE ;
178
185
}
179
-
180
- reset_normalized_uri_after_writing (internal_uri );
181
-
182
- return SUCCESS ;
183
186
}
184
187
185
188
ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_username_read (const uri_internal_t * internal_uri , uri_component_read_mode_t read_mode , zval * retval )
@@ -258,14 +261,20 @@ static zend_result php_uri_parser_rfc3986_host_write(struct uri_internal_t *inte
258
261
result = uriSetHostAutoMmA (uriparser_uri , Z_STRVAL_P (value ), Z_STRVAL_P (value ) + Z_STRLEN_P (value ), mm );
259
262
}
260
263
261
- if (result != URI_SUCCESS ) {
262
- zend_throw_exception (uri_invalid_uri_exception_ce , "The specified host is malformed" , 0 );
263
- return FAILURE ;
264
+ switch (result ) {
265
+ case URI_SUCCESS :
266
+ reset_normalized_uri_after_writing (internal_uri );
267
+ return SUCCESS ;
268
+ case URI_ERROR_SETHOST_PORT_SET :
269
+ zend_throw_exception (uri_invalid_uri_exception_ce , "Cannot remove the host from a URI that has a port" , 0 );
270
+ return FAILURE ;
271
+ case URI_ERROR_SETHOST_USERINFO_SET :
272
+ zend_throw_exception (uri_invalid_uri_exception_ce , "Cannot remove the host from a URI that has a userinfo" , 0 );
273
+ return FAILURE ;
274
+ default :
275
+ zend_throw_exception (uri_invalid_uri_exception_ce , "The specified host is malformed" , 0 );
276
+ return FAILURE ;
264
277
}
265
-
266
- reset_normalized_uri_after_writing (internal_uri );
267
-
268
- return SUCCESS ;
269
278
}
270
279
271
280
ZEND_ATTRIBUTE_NONNULL static zend_long port_str_to_zend_long_checked (const char * str , size_t len )
@@ -307,18 +316,22 @@ static zend_result php_uri_parser_rfc3986_port_write(struct uri_internal_t *inte
307
316
if (Z_TYPE_P (value ) == IS_NULL ) {
308
317
result = uriSetPortTextMmA (uriparser_uri , NULL , NULL , mm );
309
318
} else {
310
- ZVAL_STR (value , zend_long_to_str (Z_LVAL_P (value )));
311
- result = uriSetPortTextMmA (uriparser_uri , Z_STRVAL_P (value ), Z_STRVAL_P (value ) + Z_STRLEN_P (value ), mm );
312
- }
313
-
314
- if (result != URI_SUCCESS ) {
315
- zend_throw_exception (uri_invalid_uri_exception_ce , "The specified port is malformed" , 0 );
316
- return FAILURE ;
319
+ zend_string * tmp = zend_long_to_str (Z_LVAL_P (value ));
320
+ result = uriSetPortTextMmA (uriparser_uri , ZSTR_VAL (tmp ), ZSTR_VAL (tmp ) + ZSTR_LEN (tmp ), mm );
321
+ zend_string_release (tmp );
322
+ }
323
+
324
+ switch (result ) {
325
+ case URI_SUCCESS :
326
+ reset_normalized_uri_after_writing (internal_uri );
327
+ return SUCCESS ;
328
+ case URI_ERROR_SETPORT_HOST_NOT_SET :
329
+ zend_throw_exception (uri_invalid_uri_exception_ce , "Cannot set a port without having a host" , 0 );
330
+ return FAILURE ;
331
+ default :
332
+ zend_throw_exception (uri_invalid_uri_exception_ce , "The specified port is malformed" , 0 );
333
+ return FAILURE ;
317
334
}
318
-
319
- reset_normalized_uri_after_writing (internal_uri );
320
-
321
- return SUCCESS ;
322
335
}
323
336
324
337
ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_path_read (const uri_internal_t * internal_uri , uri_component_read_mode_t read_mode , zval * retval )
0 commit comments