@@ -34,6 +34,7 @@ zend_class_entry *rfc3986_uri_ce;
3434zend_object_handlers rfc3986_uri_object_handlers ;
3535zend_class_entry * whatwg_url_ce ;
3636zend_object_handlers whatwg_uri_object_handlers ;
37+ zend_class_entry * uri_comparison_mode_ce ;
3738zend_class_entry * uri_exception_ce ;
3839zend_class_entry * invalid_uri_exception_ce ;
3940zend_class_entry * whatwg_invalid_url_exception_ce ;
@@ -353,13 +354,20 @@ static zend_result pass_errors_by_ref(zval *errors_zv, zval *errors)
353354}
354355
355356PHPAPI void php_uri_instantiate_uri (
356- INTERNAL_FUNCTION_PARAMETERS , const uri_handler_t * handler , const zend_string * uri_str , const zend_string * base_url_str ,
357+ INTERNAL_FUNCTION_PARAMETERS , const uri_handler_t * handler , const zend_string * uri_str , const zend_object * base_url_object ,
357358 bool is_constructor , zval * errors_zv
358359) {
359360 zval errors ;
360361 ZVAL_UNDEF (& errors );
361362
362- void * uri = handler -> parse_uri (uri_str , base_url_str , is_constructor || errors_zv != NULL ? & errors : NULL );
363+ void * base_url = NULL ;
364+ if (base_url_object != NULL ) {
365+ uri_internal_t * internal_base_url = uri_internal_from_obj (base_url_object );
366+ URI_CHECK_INITIALIZATION (internal_base_url );
367+ base_url = internal_base_url -> uri ;
368+ }
369+
370+ void * uri = handler -> parse_uri (uri_str , base_url , is_constructor || errors_zv != NULL ? & errors : NULL );
363371 if (UNEXPECTED (uri == NULL )) {
364372 if (is_constructor ) {
365373 throw_invalid_uri_exception (handler , & errors );
@@ -389,25 +397,16 @@ PHPAPI void php_uri_instantiate_uri(
389397
390398static void create_rfc3986_uri (INTERNAL_FUNCTION_PARAMETERS , bool is_constructor )
391399{
392- zend_string * uri_str , * base_url_str = NULL ;
400+ zend_string * uri_str ;
401+ zend_object * base_url_object = NULL ;
393402
394403 ZEND_PARSE_PARAMETERS_START (1 , 2 )
395404 Z_PARAM_PATH_STR (uri_str )
396405 Z_PARAM_OPTIONAL
397- Z_PARAM_PATH_STR_OR_NULL ( base_url_str )
406+ Z_PARAM_OBJ_OF_CLASS_OR_NULL ( base_url_object , rfc3986_uri_ce )
398407 ZEND_PARSE_PARAMETERS_END ();
399408
400- if (ZSTR_LEN (uri_str ) == 0 ) {
401- zend_argument_value_error (1 , "cannot be empty" );
402- RETURN_THROWS ();
403- }
404-
405- if (base_url_str && ZSTR_LEN (base_url_str ) == 0 ) {
406- zend_argument_value_error (2 , "cannot be empty" );
407- RETURN_THROWS ();
408- }
409-
410- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & uriparser_uri_handler , uri_str , base_url_str , is_constructor , NULL );
409+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & uriparser_uri_handler , uri_str , base_url_object , is_constructor , NULL );
411410}
412411
413412PHP_METHOD (Uri_Rfc3986_Uri , parse )
@@ -422,27 +421,18 @@ PHP_METHOD(Uri_Rfc3986_Uri, __construct)
422421
423422static void create_whatwg_uri (INTERNAL_FUNCTION_PARAMETERS , bool is_constructor )
424423{
425- zend_string * uri_str , * base_url_str = NULL ;
424+ zend_string * uri_str ;
425+ zend_object * base_url_object = NULL ;
426426 zval * errors = NULL ;
427427
428428 ZEND_PARSE_PARAMETERS_START (1 , 3 )
429429 Z_PARAM_PATH_STR (uri_str )
430430 Z_PARAM_OPTIONAL
431- Z_PARAM_PATH_STR_OR_NULL ( base_url_str )
431+ Z_PARAM_OBJ_OF_CLASS_OR_NULL ( base_url_object , whatwg_url_ce )
432432 Z_PARAM_ZVAL (errors )
433433 ZEND_PARSE_PARAMETERS_END ();
434434
435- if (ZSTR_LEN (uri_str ) == 0 ) {
436- zend_argument_value_error (1 , "cannot be empty" );
437- RETURN_THROWS ();
438- }
439-
440- if (base_url_str && ZSTR_LEN (base_url_str ) == 0 ) {
441- zend_argument_value_error (2 , "cannot be empty" );
442- RETURN_THROWS ();
443- }
444-
445- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & lexbor_uri_handler , uri_str , base_url_str , is_constructor , errors );
435+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & lexbor_uri_handler , uri_str , base_url_object , is_constructor , errors );
446436}
447437
448438PHP_METHOD (Uri_WhatWg_Url , parse )
@@ -575,7 +565,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withFragment)
575565 URI_WITHER_STR_OR_NULL (ZSTR_KNOWN (ZEND_STR_FRAGMENT ));
576566}
577567
578- static void uri_equals (INTERNAL_FUNCTION_PARAMETERS , zend_object * that_object , bool exclude_fragment )
568+ static void uri_equals (INTERNAL_FUNCTION_PARAMETERS , zend_object * that_object , zend_object * comparison_mode )
579569{
580570 zend_object * this_object = Z_OBJ_P (ZEND_THIS );
581571 uri_internal_t * this_internal_uri = uri_internal_from_obj (this_object );
@@ -591,6 +581,14 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, b
591581 RETURN_FALSE ;
592582 }
593583
584+ bool exclude_fragment = true;
585+ if (comparison_mode ) {
586+ zval * case_name = zend_enum_fetch_case_name (comparison_mode );
587+ zend_string * comparison_mode_name = Z_STR_P (case_name );
588+
589+ exclude_fragment = ZSTR_VAL (comparison_mode_name )[0 ] + ZSTR_LEN (comparison_mode_name ) == 'E' + sizeof ("ExcludeFragment" ) - 1 ;
590+ }
591+
594592 zend_string * this_str = this_internal_uri -> handler -> uri_to_string (
595593 this_internal_uri -> uri , URI_RECOMPOSITION_NORMALIZED_ASCII , exclude_fragment );
596594 if (this_str == NULL ) {
@@ -614,15 +612,15 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, b
614612PHP_METHOD (Uri_Rfc3986_Uri , equals )
615613{
616614 zend_object * that_object ;
617- bool exclude_fragment = true ;
615+ zend_object * comparison_mode = NULL ;
618616
619617 ZEND_PARSE_PARAMETERS_START (1 , 2 )
620618 Z_PARAM_OBJ_OF_CLASS (that_object , rfc3986_uri_ce )
621619 Z_PARAM_OPTIONAL
622- Z_PARAM_BOOL ( exclude_fragment )
620+ Z_PARAM_OBJ_OF_CLASS ( comparison_mode , uri_comparison_mode_ce );
623621 ZEND_PARSE_PARAMETERS_END ();
624622
625- uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , exclude_fragment );
623+ uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , comparison_mode );
626624}
627625
628626PHP_METHOD (Uri_Rfc3986_Uri , toRawString )
@@ -671,14 +669,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, resolve)
671669 uri_internal_t * internal_uri = uri_internal_from_obj (this_object );
672670 URI_CHECK_INITIALIZATION (internal_uri );
673671
674- zend_string * base_uri_str = internal_uri -> handler -> uri_to_string (
675- internal_uri -> uri , URI_RECOMPOSITION_RAW_ASCII , false); // TODO optimize by not reparsing the base URI
676- if (base_uri_str == NULL ) {
677- zend_throw_exception_ex (NULL , 0 , "Cannot recompose %s to string" , ZSTR_VAL (this_object -> ce -> name ));
678- RETURN_THROWS ();
679- }
680-
681- php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , internal_uri -> handler , uri_str , base_uri_str , true, NULL );
672+ php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , internal_uri -> handler , uri_str , this_object , true, NULL );
682673}
683674
684675PHP_METHOD (Uri_Rfc3986_Uri , __serialize )
@@ -832,15 +823,15 @@ PHP_METHOD(Uri_WhatWg_Url, withHost)
832823PHP_METHOD (Uri_WhatWg_Url , equals )
833824{
834825 zend_object * that_object ;
835- bool exclude_fragment = true ;
826+ zend_object * comparison_mode = NULL ;
836827
837828 ZEND_PARSE_PARAMETERS_START (1 , 2 )
838829 Z_PARAM_OBJ_OF_CLASS (that_object , whatwg_url_ce )
839830 Z_PARAM_OPTIONAL
840- Z_PARAM_BOOL ( exclude_fragment )
831+ Z_PARAM_OBJ_OF_CLASS ( comparison_mode , uri_comparison_mode_ce );
841832 ZEND_PARSE_PARAMETERS_END ();
842833
843- uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , exclude_fragment );
834+ uri_equals (INTERNAL_FUNCTION_PARAM_PASSTHRU , that_object , comparison_mode );
844835}
845836
846837PHP_METHOD (Uri_WhatWg_Url , toUnicodeString )
@@ -955,6 +946,7 @@ static PHP_MINIT_FUNCTION(uri)
955946 whatwg_url_ce = register_class_Uri_WhatWg_Url ();
956947 php_uri_implementation_set_object_handlers (whatwg_url_ce , & whatwg_uri_object_handlers );
957948
949+ uri_comparison_mode_ce = register_class_Uri_UriComparisonMode ();
958950 uri_exception_ce = register_class_Uri_UriException (zend_ce_exception );
959951 invalid_uri_exception_ce = register_class_Uri_InvalidUriException (uri_exception_ce );
960952 whatwg_invalid_url_exception_ce = register_class_Uri_WhatWg_InvalidUrlException (invalid_uri_exception_ce );
0 commit comments