@@ -224,7 +224,7 @@ PHPAPI void php_uri_instantiate_uri(
224
224
ZEND_ASSERT (Z_TYPE (errors ) == IS_UNDEF );
225
225
226
226
if (!is_constructor ) {
227
- object_init_ex (return_value , handler -> get_uri_ce ( ));
227
+ object_init_ex (return_value , Z_CE_P ( ZEND_THIS ));
228
228
}
229
229
230
230
uri_object_t * uri_object = Z_URI_OBJECT_P (is_constructor ? ZEND_THIS : return_value );
@@ -255,7 +255,7 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor
255
255
php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & uriparser_uri_handler , uri_str , base_url_str , is_constructor , false);
256
256
}
257
257
258
- PHP_METHOD (Uri_Rfc3986Uri , create )
258
+ PHP_METHOD (Uri_Rfc3986Uri , parse )
259
259
{
260
260
create_rfc3986_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , false);
261
261
}
@@ -288,7 +288,7 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
288
288
php_uri_instantiate_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , & lexbor_uri_handler , uri_str , base_url_str , is_constructor , true);
289
289
}
290
290
291
- PHP_METHOD (Uri_WhatWgUri , create )
291
+ PHP_METHOD (Uri_WhatWgUri , parse )
292
292
{
293
293
create_whatwg_uri (INTERNAL_FUNCTION_PARAM_PASSTHRU , false);
294
294
}
@@ -403,13 +403,57 @@ PHP_METHOD(Uri_Rfc3986Uri, equalsTo)
403
403
RETURN_FALSE ;
404
404
}
405
405
406
- zend_string * this_str = this_internal_uri -> handler -> uri_to_string (this_internal_uri -> uri , exclude_fragment );
406
+ void * this_uri , * that_uri ;
407
+
408
+ if (this_internal_uri -> handler -> normalize_uri != NULL ) {
409
+ this_uri = this_internal_uri -> handler -> clone_uri (this_internal_uri -> uri );
410
+ if (UNEXPECTED (this_uri == NULL )) {
411
+ zend_throw_error (uri_operation_exception_ce , "Failed to normalize %s" , ZSTR_VAL (this_object -> ce -> name ));
412
+ RETURN_THROWS ();
413
+ }
414
+
415
+ zend_result result = this_internal_uri -> handler -> normalize_uri (this_uri );
416
+ if (UNEXPECTED (result == FAILURE )) {
417
+ zend_throw_error (uri_operation_exception_ce , "Failed to normalize %s" , ZSTR_VAL (this_object -> ce -> name ));
418
+ this_internal_uri -> handler -> free_uri (this_uri );
419
+ RETURN_THROWS ();
420
+ }
421
+ } else {
422
+ this_uri = this_internal_uri -> uri ;
423
+ }
424
+
425
+ if (that_internal_uri -> handler -> normalize_uri != NULL ) {
426
+ that_uri = that_internal_uri -> handler -> clone_uri (that_internal_uri -> uri );
427
+ if (UNEXPECTED (that_uri == NULL )) {
428
+ zend_throw_error (uri_operation_exception_ce , "Failed to normalize %s" , ZSTR_VAL (that_object -> ce -> name ));
429
+ RETURN_THROWS ();
430
+ }
431
+
432
+ zend_result result = that_internal_uri -> handler -> normalize_uri (that_uri );
433
+ if (UNEXPECTED (result == FAILURE )) {
434
+ zend_throw_error (uri_operation_exception_ce , "Failed to normalize %s" , ZSTR_VAL (that_object -> ce -> name ));
435
+ that_internal_uri -> handler -> free_uri (that_uri );
436
+ RETURN_THROWS ();
437
+ }
438
+ } else {
439
+ that_uri = that_internal_uri -> uri ;
440
+ }
441
+
442
+ zend_string * this_str = this_internal_uri -> handler -> uri_to_string (this_internal_uri -> uri , exclude_fragment ); // TODO what happens if the __clone() method is overridden?
407
443
zend_string * that_str = that_internal_uri -> handler -> uri_to_string (that_internal_uri -> uri , exclude_fragment );
408
444
409
445
RETVAL_BOOL (zend_string_equals (this_str , that_str ));
410
446
411
447
zend_string_release (this_str );
412
448
zend_string_release (that_str );
449
+
450
+ if (this_internal_uri -> handler -> normalize_uri != NULL ) {
451
+ this_internal_uri -> handler -> free_uri (this_uri );
452
+ }
453
+
454
+ if (that_internal_uri -> handler -> normalize_uri != NULL ) {
455
+ that_internal_uri -> handler -> free_uri (that_uri );
456
+ }
413
457
}
414
458
415
459
PHP_METHOD (Uri_Rfc3986Uri , normalize )
@@ -420,6 +464,10 @@ PHP_METHOD(Uri_Rfc3986Uri, normalize)
420
464
uri_internal_t * internal_uri = uri_internal_from_obj (this_object );
421
465
URI_CHECK_INITIALIZATION_RETURN_THROWS (internal_uri , this_object );
422
466
467
+ if (internal_uri -> handler -> normalize_uri == NULL ) {
468
+ RETURN_COPY (ZEND_THIS );
469
+ }
470
+
423
471
zend_object * new_object = uri_clone_obj_handler (this_object );
424
472
if (UNEXPECTED (EG (exception ) != NULL )) {
425
473
zend_object_release (new_object );
@@ -446,6 +494,10 @@ PHP_METHOD(Uri_Rfc3986Uri, toNormalizedString)
446
494
uri_internal_t * internal_uri = uri_internal_from_obj (object );
447
495
URI_CHECK_INITIALIZATION_RETURN_THROWS (internal_uri , object );
448
496
497
+ if (internal_uri -> handler -> normalize_uri == NULL ) {
498
+ RETURN_STR (internal_uri -> handler -> uri_to_string (internal_uri -> uri , false));
499
+ }
500
+
449
501
void * new_uri = internal_uri -> handler -> clone_uri (internal_uri -> uri );
450
502
if (UNEXPECTED (new_uri == NULL )) {
451
503
zend_throw_error (uri_operation_exception_ce , "Failed to normalize %s" , ZSTR_VAL (object -> ce -> name ));
@@ -513,12 +565,13 @@ PHP_METHOD(Uri_Rfc3986Uri, __unserialize)
513
565
zend_object * object = Z_OBJ_P (ZEND_THIS );
514
566
uri_internal_t * internal_uri = uri_internal_from_obj (object );
515
567
516
- zend_string * str = zend_string_init ("https://example.com" , sizeof ("https://example.com" ) - 1 , false);
568
+ zend_string * str = zend_string_init ("https://example.com" , sizeof ("https://example.com" ) - 1 , false); // TODO set URI components from ht
517
569
518
570
zval errors ;
519
571
ZVAL_UNDEF (& errors );
520
572
521
573
internal_uri -> handler = uri_handler_by_name (URI_PARSER_RFC3986 , sizeof (URI_PARSER_RFC3986 ) - 1 );
574
+ // TODO free current URI if any
522
575
internal_uri -> uri = internal_uri -> handler -> parse_uri (str , NULL , & errors );
523
576
if (internal_uri -> uri == NULL ) {
524
577
throw_invalid_uri_exception (& errors );
@@ -543,12 +596,13 @@ PHP_METHOD(Uri_WhatWgUri, __unserialize)
543
596
zend_object * object = Z_OBJ_P (ZEND_THIS );
544
597
uri_internal_t * internal_uri = uri_internal_from_obj (object );
545
598
546
- zend_string * str = zend_string_init ("https://example.com" , sizeof ("https://example.com" ) - 1 , false);
599
+ zend_string * str = zend_string_init ("https://example.com" , sizeof ("https://example.com" ) - 1 , false); // TODO set URI components from ht
547
600
548
601
zval errors ;
549
602
ZVAL_UNDEF (& errors );
550
603
551
604
internal_uri -> handler = uri_handler_by_name (URI_PARSER_WHATWG , sizeof (URI_PARSER_WHATWG ) - 1 );
605
+ // TODO free current URI if any
552
606
internal_uri -> uri = internal_uri -> handler -> parse_uri (str , NULL , & errors );
553
607
if (internal_uri -> uri == NULL ) {
554
608
throw_invalid_uri_exception (& errors );
@@ -708,7 +762,7 @@ static zend_object *uri_clone_obj_handler(zend_object *object)
708
762
709
763
new_uri_object -> internal .handler = internal_uri -> handler ;
710
764
711
- void * uri = internal_uri -> handler -> clone_uri (internal_uri -> uri );
765
+ void * uri = internal_uri -> handler -> clone_uri (internal_uri -> uri ); // TODO what happens if the __clone() method is overridden?
712
766
if (UNEXPECTED (uri == NULL )) {
713
767
zend_throw_error (uri_operation_exception_ce , "Failed to clone %s" , ZSTR_VAL (object -> ce -> name ));
714
768
return & new_uri_object -> std ;
@@ -773,9 +827,8 @@ zend_result uri_handler_register(const uri_handler_t *uri_handler)
773
827
ZEND_ASSERT (uri_handler -> name != NULL );
774
828
ZEND_ASSERT (uri_handler -> init_parser != NULL );
775
829
ZEND_ASSERT (uri_handler -> parse_uri != NULL );
776
- ZEND_ASSERT (uri_handler -> get_uri_ce != NULL );
830
+ ZEND_ASSERT (uri_handler -> get_uri_ce != NULL ); // TODO unused handler, maybe remove?
777
831
ZEND_ASSERT (uri_handler -> clone_uri != NULL );
778
- ZEND_ASSERT (uri_handler -> normalize_uri != NULL );
779
832
ZEND_ASSERT (uri_handler -> uri_to_string != NULL );
780
833
ZEND_ASSERT (uri_handler -> free_uri != NULL );
781
834
ZEND_ASSERT (uri_handler -> destroy_parser != NULL );
0 commit comments