From 8e21e6760056fc24954ec36c06124aa2f331afa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Mon, 18 Nov 2024 22:17:57 +0100 Subject: [PATCH] Some cleanups --- ext/filter/tests/062.phpt | 28 ++++--- ext/uri/php_lexbor.c | 8 +- ext/uri/php_uri.c | 71 +++++++++++++++--- ext/uri/php_uri.stub.php | 6 +- ext/uri/php_uri_arginfo.h | 16 ++-- ext/uri/php_uriparser.c | 2 +- ext/uri/tests/001.phpt | 8 +- ext/uri/tests/002.phpt | 8 +- ext/uri/tests/003.phpt | 8 +- ext/uri/tests/004.phpt | 24 +++--- ext/uri/tests/005.phpt | 4 +- ext/uri/tests/008.phpt | 4 +- ext/uri/tests/009.phpt | 4 +- ext/uri/tests/010.phpt | 8 +- ext/uri/tests/011.phpt | 20 ++--- ext/uri/tests/012.phpt | 8 +- ext/uri/tests/013.phpt | 16 ++-- ext/uri/tests/014.phpt | 4 +- ext/uri/tests/016.phpt | 4 +- ext/uri/tests/018.phpt | 4 +- ext/uri/tests/019.phpt | 4 +- ext/uri/tests/023.phpt | 4 +- ext/uri/tests/024.phpt | 4 +- ext/uri/tests/025.phpt | 4 +- ext/uri/tests/026.phpt | 10 +-- ext/uri/tests/027.phpt | 8 +- ext/uri/tests/028.phpt | 10 +-- ext/uri/tests/029.phpt | 8 +- ext/uri/tests/030.phpt | 8 +- ext/uri/tests/036.phpt | 150 +++++++++++++++++++++++++++++++++++--- ext/uri/tests/037.phpt | 106 ++++++++++++++++++++++----- ext/uri/tests/038.phpt | 12 +-- 32 files changed, 415 insertions(+), 168 deletions(-) diff --git a/ext/filter/tests/062.phpt b/ext/filter/tests/062.phpt index 6c7ec5558918c..f2acc1f3139f1 100644 --- a/ext/filter/tests/062.phpt +++ b/ext/filter/tests/062.phpt @@ -5,7 +5,7 @@ filter --FILE-- $parserName])); } - var_dump(filter_var("qwe", FILTER_VALIDATE_URL)); - var_dump(filter_var("http://qwe", FILTER_VALIDATE_URL)); - var_dump(filter_var("http://", FILTER_VALIDATE_URL)); - var_dump(filter_var("/tmp/test", FILTER_VALIDATE_URL)); - var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL)); - var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)); - var_dump(filter_var("http://www.example.com/path/at/the/server/", FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)); - var_dump(filter_var("http://www.example.com/index.html", FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED)); - var_dump(filter_var("http://www.example.com/index.php?a=b&c=d", FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED)); + var_dump(filter_var("qwe", FILTER_VALIDATE_URL, ["parser" => $parserName])); + var_dump(filter_var("http://qwe", FILTER_VALIDATE_URL, ["parser" => $parserName])); + var_dump(filter_var("http://", FILTER_VALIDATE_URL, ["parser" => $parserName])); + var_dump(filter_var("/tmp/test", FILTER_VALIDATE_URL, ["parser" => $parserName])); + var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["parser" => $parserName])); + var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED])); + var_dump(filter_var("http://www.example.com/path/at/the/server/", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED])); + var_dump(filter_var("http://www.example.com/index.html", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED])); + var_dump(filter_var("http://www.example.com/index.php?a=b&c=d", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED])); } echo "RFC3986:\n"; -ini_set("uri.default_handler", "rfc3986"); -validateUrls(); +validateUrls(Uri\URI_PARSER_RFC3986); echo "\nWHATWG:\n"; -ini_set("uri.default_handler", "whatwg"); -validateUrls(); +validateUrls(Uri\URI_PARSER_WHATWG); echo "Done\n"; ?> diff --git a/ext/uri/php_lexbor.c b/ext/uri/php_lexbor.c index 62cd5e7c57f3e..918977fc25acc 100644 --- a/ext/uri/php_lexbor.c +++ b/ext/uri/php_lexbor.c @@ -27,7 +27,6 @@ static zend_result lexbor_init_parser(void); static void *lexbor_parse_uri(const zend_string *url_str, const zend_string *base_url_str, zval *errors); static zend_class_entry *lexbor_get_uri_ce(void); static void *lexbor_clone_uri(void *uri); -static zend_result lexbor_normalize_uri(void *uri); static zend_string *lexbor_uri_to_string(void *uri, bool exclude_fragment); static void lexbor_free_uri(void *uri); static zend_result lexbor_destroy_parser(void); @@ -43,7 +42,7 @@ const uri_handler_t lexbor_uri_handler = { lexbor_parse_uri, lexbor_get_uri_ce, lexbor_clone_uri, - lexbor_normalize_uri, + NULL, lexbor_uri_to_string, lexbor_free_uri, lexbor_destroy_parser, @@ -383,11 +382,6 @@ static void *lexbor_clone_uri(void *uri) return lxb_url_clone(lexbor_parser->mraw, lexbor_uri); } -static zend_result lexbor_normalize_uri(void *uri) -{ - return SUCCESS; -} - static lxb_status_t lexbor_serialize_callback(const lxb_char_t *data, size_t length, void *ctx) { smart_str *uri_str = (smart_str *) ctx; diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c index 2cf82fffcc464..25a91b64995a6 100644 --- a/ext/uri/php_uri.c +++ b/ext/uri/php_uri.c @@ -224,7 +224,7 @@ PHPAPI void php_uri_instantiate_uri( ZEND_ASSERT(Z_TYPE(errors) == IS_UNDEF); if (!is_constructor) { - object_init_ex(return_value, handler->get_uri_ce()); + object_init_ex(return_value, Z_CE_P(ZEND_THIS)); } 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 php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, &uriparser_uri_handler, uri_str, base_url_str, is_constructor, false); } -PHP_METHOD(Uri_Rfc3986Uri, create) +PHP_METHOD(Uri_Rfc3986Uri, parse) { create_rfc3986_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); } @@ -288,7 +288,7 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor) php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, &lexbor_uri_handler, uri_str, base_url_str, is_constructor, true); } -PHP_METHOD(Uri_WhatWgUri, create) +PHP_METHOD(Uri_WhatWgUri, parse) { create_whatwg_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); } @@ -403,13 +403,57 @@ PHP_METHOD(Uri_Rfc3986Uri, equalsTo) RETURN_FALSE; } - zend_string *this_str = this_internal_uri->handler->uri_to_string(this_internal_uri->uri, exclude_fragment); + void *this_uri, *that_uri; + + if (this_internal_uri->handler->normalize_uri != NULL) { + this_uri = this_internal_uri->handler->clone_uri(this_internal_uri->uri); + if (UNEXPECTED(this_uri == NULL)) { + zend_throw_error(uri_operation_exception_ce, "Failed to normalize %s", ZSTR_VAL(this_object->ce->name)); + RETURN_THROWS(); + } + + zend_result result = this_internal_uri->handler->normalize_uri(this_uri); + if (UNEXPECTED(result == FAILURE)) { + zend_throw_error(uri_operation_exception_ce, "Failed to normalize %s", ZSTR_VAL(this_object->ce->name)); + this_internal_uri->handler->free_uri(this_uri); + RETURN_THROWS(); + } + } else { + this_uri = this_internal_uri->uri; + } + + if (that_internal_uri->handler->normalize_uri != NULL) { + that_uri = that_internal_uri->handler->clone_uri(that_internal_uri->uri); + if (UNEXPECTED(that_uri == NULL)) { + zend_throw_error(uri_operation_exception_ce, "Failed to normalize %s", ZSTR_VAL(that_object->ce->name)); + RETURN_THROWS(); + } + + zend_result result = that_internal_uri->handler->normalize_uri(that_uri); + if (UNEXPECTED(result == FAILURE)) { + zend_throw_error(uri_operation_exception_ce, "Failed to normalize %s", ZSTR_VAL(that_object->ce->name)); + that_internal_uri->handler->free_uri(that_uri); + RETURN_THROWS(); + } + } else { + that_uri = that_internal_uri->uri; + } + + 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? zend_string *that_str = that_internal_uri->handler->uri_to_string(that_internal_uri->uri, exclude_fragment); RETVAL_BOOL(zend_string_equals(this_str, that_str)); zend_string_release(this_str); zend_string_release(that_str); + + if (this_internal_uri->handler->normalize_uri != NULL) { + this_internal_uri->handler->free_uri(this_uri); + } + + if (that_internal_uri->handler->normalize_uri != NULL) { + that_internal_uri->handler->free_uri(that_uri); + } } PHP_METHOD(Uri_Rfc3986Uri, normalize) @@ -420,6 +464,10 @@ PHP_METHOD(Uri_Rfc3986Uri, normalize) uri_internal_t *internal_uri = uri_internal_from_obj(this_object); URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, this_object); + if (internal_uri->handler->normalize_uri == NULL) { + RETURN_COPY(ZEND_THIS); + } + zend_object *new_object = uri_clone_obj_handler(this_object); if (UNEXPECTED(EG(exception) != NULL)) { zend_object_release(new_object); @@ -446,6 +494,10 @@ PHP_METHOD(Uri_Rfc3986Uri, toNormalizedString) uri_internal_t *internal_uri = uri_internal_from_obj(object); URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, object); + if (internal_uri->handler->normalize_uri == NULL) { + RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, false)); + } + void *new_uri = internal_uri->handler->clone_uri(internal_uri->uri); if (UNEXPECTED(new_uri == NULL)) { 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) zend_object *object = Z_OBJ_P(ZEND_THIS); uri_internal_t *internal_uri = uri_internal_from_obj(object); - zend_string *str = zend_string_init("https://example.com", sizeof("https://example.com") - 1, false); + zend_string *str = zend_string_init("https://example.com", sizeof("https://example.com") - 1, false); // TODO set URI components from ht zval errors; ZVAL_UNDEF(&errors); internal_uri->handler = uri_handler_by_name(URI_PARSER_RFC3986, sizeof(URI_PARSER_RFC3986) - 1); + // TODO free current URI if any internal_uri->uri = internal_uri->handler->parse_uri(str, NULL, &errors); if (internal_uri->uri == NULL) { throw_invalid_uri_exception(&errors); @@ -543,12 +596,13 @@ PHP_METHOD(Uri_WhatWgUri, __unserialize) zend_object *object = Z_OBJ_P(ZEND_THIS); uri_internal_t *internal_uri = uri_internal_from_obj(object); - zend_string *str = zend_string_init("https://example.com", sizeof("https://example.com") - 1, false); + zend_string *str = zend_string_init("https://example.com", sizeof("https://example.com") - 1, false); // TODO set URI components from ht zval errors; ZVAL_UNDEF(&errors); internal_uri->handler = uri_handler_by_name(URI_PARSER_WHATWG, sizeof(URI_PARSER_WHATWG) - 1); + // TODO free current URI if any internal_uri->uri = internal_uri->handler->parse_uri(str, NULL, &errors); if (internal_uri->uri == NULL) { throw_invalid_uri_exception(&errors); @@ -708,7 +762,7 @@ static zend_object *uri_clone_obj_handler(zend_object *object) new_uri_object->internal.handler = internal_uri->handler; - void *uri = internal_uri->handler->clone_uri(internal_uri->uri); + void *uri = internal_uri->handler->clone_uri(internal_uri->uri); // TODO what happens if the __clone() method is overridden? if (UNEXPECTED(uri == NULL)) { zend_throw_error(uri_operation_exception_ce, "Failed to clone %s", ZSTR_VAL(object->ce->name)); return &new_uri_object->std; @@ -773,9 +827,8 @@ zend_result uri_handler_register(const uri_handler_t *uri_handler) ZEND_ASSERT(uri_handler->name != NULL); ZEND_ASSERT(uri_handler->init_parser != NULL); ZEND_ASSERT(uri_handler->parse_uri != NULL); - ZEND_ASSERT(uri_handler->get_uri_ce != NULL); + ZEND_ASSERT(uri_handler->get_uri_ce != NULL); // TODO unused handler, maybe remove? ZEND_ASSERT(uri_handler->clone_uri != NULL); - ZEND_ASSERT(uri_handler->normalize_uri != NULL); ZEND_ASSERT(uri_handler->uri_to_string != NULL); ZEND_ASSERT(uri_handler->free_uri != NULL); ZEND_ASSERT(uri_handler->destroy_parser != NULL); diff --git a/ext/uri/php_uri.stub.php b/ext/uri/php_uri.stub.php index 01ae791ea90dc..c1abc52c366c7 100644 --- a/ext/uri/php_uri.stub.php +++ b/ext/uri/php_uri.stub.php @@ -38,7 +38,7 @@ class InvalidUriException extends \Uri\UriException } /** @strict-properties */ -final readonly class WhatWgError +readonly class WhatWgError { /** @cvalue LXB_URL_ERROR_TYPE_DOMAIN_TO_ASCII */ public const int ERROR_TYPE_DOMAIN_TO_ASCII = UNKNOWN; @@ -168,7 +168,7 @@ public function __toString(): string {} /** @virtual */ private ?string $fragment; - public static function create(string $uri, ?string $baseUrl = null): ?static {} + public static function parse(string $uri, ?string $baseUrl = null): ?static {} public function __construct(string $uri, ?string $baseUrl = null) {} @@ -237,7 +237,7 @@ public function __unserialize(array $data): void; /** @virtual */ private ?string $fragment; - public static function create(string $uri, ?string $baseUrl = null): static|array {} + public static function parse(string $uri, ?string $baseUrl = null): static|array {} public function __construct(string $uri, ?string $baseUrl = null) {} diff --git a/ext/uri/php_uri_arginfo.h b/ext/uri/php_uri_arginfo.h index a8f0aadbe8c03..e6b7ed8afef94 100644 --- a/ext/uri/php_uri_arginfo.h +++ b/ext/uri/php_uri_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d82582ee301cdb3c1b3a14101e1a189141810262 */ + * Stub hash: e2c069ed3efafce65c85e844b5be4a94dd4d9744 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Uri_WhatWgError___construct, 0, 0, 3) ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0) @@ -70,7 +70,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_Uri_UriInterface___toString arginfo_class_Uri_UriInterface_toNormalizedString -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986Uri_create, 0, 1, IS_STATIC, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986Uri_parse, 0, 1, IS_STATIC, 1) ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, baseUrl, IS_STRING, 1, "null") ZEND_END_ARG_INFO() @@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986Uri___unseriali ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Uri_WhatWgUri_create, 0, 1, MAY_BE_STATIC|MAY_BE_ARRAY) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Uri_WhatWgUri_parse, 0, 1, MAY_BE_STATIC|MAY_BE_ARRAY) ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, baseUrl, IS_STRING, 1, "null") ZEND_END_ARG_INFO() @@ -179,7 +179,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_Uri_WhatWgUri___unserialize arginfo_class_Uri_Rfc3986Uri___unserialize ZEND_METHOD(Uri_WhatWgError, __construct); -ZEND_METHOD(Uri_Rfc3986Uri, create); +ZEND_METHOD(Uri_Rfc3986Uri, parse); ZEND_METHOD(Uri_Rfc3986Uri, __construct); ZEND_METHOD(Uri_Rfc3986Uri, getScheme); ZEND_METHOD(Uri_Rfc3986Uri, withScheme); @@ -203,7 +203,7 @@ ZEND_METHOD(Uri_Rfc3986Uri, toNormalizedString); ZEND_METHOD(Uri_Rfc3986Uri, __toString); ZEND_METHOD(Uri_Rfc3986Uri, __serialize); ZEND_METHOD(Uri_Rfc3986Uri, __unserialize); -ZEND_METHOD(Uri_WhatWgUri, create); +ZEND_METHOD(Uri_WhatWgUri, parse); ZEND_METHOD(Uri_WhatWgUri, __construct); ZEND_METHOD(Uri_WhatWgUri, __unserialize); @@ -237,7 +237,7 @@ static const zend_function_entry class_Uri_UriInterface_methods[] = { }; static const zend_function_entry class_Uri_Rfc3986Uri_methods[] = { - ZEND_ME(Uri_Rfc3986Uri, create, arginfo_class_Uri_Rfc3986Uri_create, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME(Uri_Rfc3986Uri, parse, arginfo_class_Uri_Rfc3986Uri_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(Uri_Rfc3986Uri, __construct, arginfo_class_Uri_Rfc3986Uri___construct, ZEND_ACC_PUBLIC) ZEND_ME(Uri_Rfc3986Uri, getScheme, arginfo_class_Uri_Rfc3986Uri_getScheme, ZEND_ACC_PUBLIC) ZEND_ME(Uri_Rfc3986Uri, withScheme, arginfo_class_Uri_Rfc3986Uri_withScheme, ZEND_ACC_PUBLIC) @@ -265,7 +265,7 @@ static const zend_function_entry class_Uri_Rfc3986Uri_methods[] = { }; static const zend_function_entry class_Uri_WhatWgUri_methods[] = { - ZEND_ME(Uri_WhatWgUri, create, arginfo_class_Uri_WhatWgUri_create, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME(Uri_WhatWgUri, parse, arginfo_class_Uri_WhatWgUri_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(Uri_WhatWgUri, __construct, arginfo_class_Uri_WhatWgUri___construct, ZEND_ACC_PUBLIC) ZEND_RAW_FENTRY("getScheme", zim_Uri_Rfc3986Uri_getScheme, arginfo_class_Uri_WhatWgUri_getScheme, ZEND_ACC_PUBLIC, NULL, NULL) ZEND_RAW_FENTRY("withScheme", zim_Uri_Rfc3986Uri_withScheme, arginfo_class_Uri_WhatWgUri_withScheme, ZEND_ACC_PUBLIC, NULL, NULL) @@ -349,7 +349,7 @@ static zend_class_entry *register_class_Uri_WhatWgError(void) zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "Uri", "WhatWgError", class_Uri_WhatWgError_methods); - class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_READONLY_CLASS); + class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_READONLY_CLASS); zval const_ERROR_TYPE_DOMAIN_TO_ASCII_value; ZVAL_LONG(&const_ERROR_TYPE_DOMAIN_TO_ASCII_value, LXB_URL_ERROR_TYPE_DOMAIN_TO_ASCII); diff --git a/ext/uri/php_uriparser.c b/ext/uri/php_uriparser.c index 5d8047526bba8..18902d50f8db0 100644 --- a/ext/uri/php_uriparser.c +++ b/ext/uri/php_uriparser.c @@ -341,7 +341,7 @@ static zend_result uriparser_write_port(uri_internal_t *internal_uri, zval *valu uriparser_append_authority(internal_uri, &uri_str); uriparser_append_host(internal_uri, &uri_str); - if (Z_TYPE_P(value) == IS_LONG && Z_LVAL_P(value) != 0) { + if (Z_TYPE_P(value) == IS_LONG) { smart_str_appendc(&uri_str, ':'); smart_str_append_long(&uri_str, Z_LVAL_P(value)); } diff --git a/ext/uri/tests/001.phpt b/ext/uri/tests/001.phpt index 3286c3998fff2..2787b2974f4dd 100644 --- a/ext/uri/tests/001.phpt +++ b/ext/uri/tests/001.phpt @@ -7,13 +7,13 @@ uri $t1 = hrtime(true); for ($i = 0; $i < 1000; $i++) { - Uri\Rfc3986Uri::create("https://example.com"); + Uri\Rfc3986Uri::parse("https://example.com"); } $t2 = hrtime(true); $t3 = hrtime(true); for ($i = 0; $i < 1000; $i++) { - Uri\WhatWgUri::create("https://example.com/"); + Uri\WhatWgUri::parse("https://example.com/"); } $t4 = hrtime(true); @@ -25,12 +25,12 @@ $t6 = hrtime(true); echo "RFC 3986 parser: https://example.com\n"; var_dump(($t2 - $t1) / 1_000_000_000); -var_dump(Uri\Rfc3986Uri::create("https://example.com")); +var_dump(Uri\Rfc3986Uri::parse("https://example.com")); echo "------------------------\n"; echo "WHATWG parser: https://example.com\n"; var_dump(($t4 - $t3) / 1_000_000_000); -var_dump(Uri\WhatWgUri::create("https://example.com")); +var_dump(Uri\WhatWgUri::parse("https://example.com")); echo "------------------------\n"; echo "PHP parser: https://example.com\n"; diff --git a/ext/uri/tests/002.phpt b/ext/uri/tests/002.phpt index 32344042d27a8..da068b262131b 100644 --- a/ext/uri/tests/002.phpt +++ b/ext/uri/tests/002.phpt @@ -7,13 +7,13 @@ uri $t1 = hrtime(true); for ($i = 0; $i < 1000; $i++) { - Uri\Rfc3986Uri::create("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); + Uri\Rfc3986Uri::parse("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); } $t2 = hrtime(true); $t3 = hrtime(true); for ($i = 0; $i < 1000; $i++) { - Uri\WhatWgUri::create("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); + Uri\WhatWgUri::parse("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); } $t4 = hrtime(true); @@ -25,12 +25,12 @@ $t6 = hrtime(true); echo "RFC 3986 parser:\n"; var_dump(($t2 - $t1) / 1_000_000_000); -var_dump(Uri\Rfc3986Uri::create("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists")); +var_dump(Uri\Rfc3986Uri::parse("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists")); echo "------------------------\n"; echo "WHATWG parser:\n"; var_dump(($t4 - $t3) / 1_000_000_000); -var_dump(Uri\WhatWgUri::create("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists")); +var_dump(Uri\WhatWgUri::parse("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists")); echo "------------------------\n"; echo "parse_url:\n"; diff --git a/ext/uri/tests/003.phpt b/ext/uri/tests/003.phpt index 3d77382347636..a5ad175bd79ff 100644 --- a/ext/uri/tests/003.phpt +++ b/ext/uri/tests/003.phpt @@ -5,11 +5,11 @@ uri --FILE-- --EXPECTF-- diff --git a/ext/uri/tests/004.phpt b/ext/uri/tests/004.phpt index 427579509d919..dbd2198e05ea0 100644 --- a/ext/uri/tests/004.phpt +++ b/ext/uri/tests/004.phpt @@ -12,7 +12,7 @@ try { } try { - Uri\Rfc3986Uri::create(""); + Uri\Rfc3986Uri::parse(""); } catch (ValueError $e) { echo $e->getMessage() . "\n"; } @@ -24,13 +24,13 @@ try { } try { - Uri\WhatWgUri::create(""); + Uri\WhatWgUri::parse(""); } catch (ValueError $e) { echo $e->getMessage() . "\n"; } try { - Uri\Rfc3986Uri::create("https://example.com", ""); + Uri\Rfc3986Uri::parse("https://example.com", ""); } catch (ValueError $e) { echo $e->getMessage() . "\n"; } @@ -48,27 +48,27 @@ try { } try { - Uri\WhatWgUri::create("https://example.com", ""); + Uri\WhatWgUri::parse("https://example.com", ""); } catch (ValueError $e) { echo $e->getMessage() . "\n"; } -var_dump(Uri\Rfc3986Uri::create("192.168/contact.html")); -var_dump(Uri\WhatWgUri::create("192.168/contact.html", null)); +var_dump(Uri\Rfc3986Uri::parse("192.168/contact.html")); +var_dump(Uri\WhatWgUri::parse("192.168/contact.html", null)); -var_dump(Uri\Rfc3986Uri::create("http://RuPaul's Drag Race All Stars 7 Winners Cast on This Season's")); -var_dump(Uri\WhatWgUri::create("http://RuPaul's Drag Race All Stars 7 Winners Cast on This Season's", null)); +var_dump(Uri\Rfc3986Uri::parse("http://RuPaul's Drag Race All Stars 7 Winners Cast on This Season's")); +var_dump(Uri\WhatWgUri::parse("http://RuPaul's Drag Race All Stars 7 Winners Cast on This Season's", null)); ?> --EXPECTF-- Uri\Rfc3986Uri::__construct(): Argument #1 ($uri) cannot be empty -Uri\Rfc3986Uri::create(): Argument #1 ($uri) cannot be empty +Uri\Rfc3986Uri::parse(): Argument #1 ($uri) cannot be empty Uri\WhatWgUri::__construct(): Argument #1 ($uri) cannot be empty -Uri\WhatWgUri::create(): Argument #1 ($uri) cannot be empty -Uri\Rfc3986Uri::create(): Argument #2 ($baseUrl) cannot be empty +Uri\WhatWgUri::parse(): Argument #1 ($uri) cannot be empty +Uri\Rfc3986Uri::parse(): Argument #2 ($baseUrl) cannot be empty Uri\Rfc3986Uri::__construct(): Argument #2 ($baseUrl) cannot be empty Uri\WhatWgUri::__construct(): Argument #2 ($baseUrl) cannot be empty -Uri\WhatWgUri::create(): Argument #2 ($baseUrl) cannot be empty +Uri\WhatWgUri::parse(): Argument #2 ($baseUrl) cannot be empty object(Uri\Rfc3986Uri)#%d (%d) { ["scheme"]=> NULL diff --git a/ext/uri/tests/005.phpt b/ext/uri/tests/005.phpt index df249c009b12d..d53e2b26304d9 100644 --- a/ext/uri/tests/005.phpt +++ b/ext/uri/tests/005.phpt @@ -5,9 +5,9 @@ uri --FILE-- __toString()); diff --git a/ext/uri/tests/008.phpt b/ext/uri/tests/008.phpt index c9ad98eba70a5..90c24278f4e93 100644 --- a/ext/uri/tests/008.phpt +++ b/ext/uri/tests/008.phpt @@ -17,12 +17,12 @@ function callGetters(Uri\UriInterface $uri) var_dump($uri->getFragment()); } -$uri = Uri\Rfc3986Uri::create("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); +$uri = Uri\Rfc3986Uri::parse("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); callGetters($uri); echo "\n"; -$uri = Uri\WhatWgUri::create("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); +$uri = Uri\WhatWgUri::parse("https://username:password@www.google.com:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); callGetters($uri); ?> diff --git a/ext/uri/tests/009.phpt b/ext/uri/tests/009.phpt index 3025e066e69ca..d50d8f474853a 100644 --- a/ext/uri/tests/009.phpt +++ b/ext/uri/tests/009.phpt @@ -5,8 +5,8 @@ uri --FILE-- --EXPECTF-- diff --git a/ext/uri/tests/010.phpt b/ext/uri/tests/010.phpt index 44c7b8e4f2999..678577ec231f8 100644 --- a/ext/uri/tests/010.phpt +++ b/ext/uri/tests/010.phpt @@ -5,10 +5,10 @@ uri --FILE-- --EXPECTF-- diff --git a/ext/uri/tests/011.phpt b/ext/uri/tests/011.phpt index 7a69fadd363b7..a673d3918042a 100644 --- a/ext/uri/tests/011.phpt +++ b/ext/uri/tests/011.phpt @@ -5,17 +5,17 @@ uri --FILE-- __toString()); -var_dump(Uri\Rfc3986Uri::create("https://www.example.com/dir1/../dir2")->__toString()); -var_dump(Uri\Rfc3986Uri::create("https://你好你好")); -var_dump(Uri\Rfc3986Uri::create("https://0Xc0.0250.01")); -var_dump(Uri\Rfc3986Uri::create("HttPs://0300.0250.0000.0001/path?query=foo%20bar")->__toString()); +var_dump(Uri\Rfc3986Uri::parse("http://////www.EXAMPLE.com:80")->__toString()); +var_dump(Uri\Rfc3986Uri::parse("https://www.example.com/dir1/../dir2")->__toString()); +var_dump(Uri\Rfc3986Uri::parse("https://你好你好")); +var_dump(Uri\Rfc3986Uri::parse("https://0Xc0.0250.01")); +var_dump(Uri\Rfc3986Uri::parse("HttPs://0300.0250.0000.0001/path?query=foo%20bar")->__toString()); -var_dump(Uri\WhatWgUri::create("http://////www.EXAMPLE.com:80")->__toString()); -var_dump(Uri\WhatWgUri::create("https://www.example.com:443/dir1/../dir2")->__toString()); -var_dump(Uri\WhatWgUri::create("https://你好你好")->__toString()); -var_dump(Uri\WhatWgUri::create("https://0Xc0.0250.01")->__toString()); -var_dump(Uri\WhatWgUri::create("HttPs://0300.0250.0000.0001/path?query=foo%20bar")->__toString()); +var_dump(Uri\WhatWgUri::parse("http://////www.EXAMPLE.com:80")->__toString()); +var_dump(Uri\WhatWgUri::parse("https://www.example.com:443/dir1/../dir2")->__toString()); +var_dump(Uri\WhatWgUri::parse("https://你好你好")->__toString()); +var_dump(Uri\WhatWgUri::parse("https://0Xc0.0250.01")->__toString()); +var_dump(Uri\WhatWgUri::parse("HttPs://0300.0250.0000.0001/path?query=foo%20bar")->__toString()); ?> --EXPECT-- diff --git a/ext/uri/tests/012.phpt b/ext/uri/tests/012.phpt index 1bc50a1ea5bb6..424595c0ab46a 100644 --- a/ext/uri/tests/012.phpt +++ b/ext/uri/tests/012.phpt @@ -5,11 +5,11 @@ uri --FILE-- --EXPECTF-- diff --git a/ext/uri/tests/013.phpt b/ext/uri/tests/013.phpt index f3080c084371a..b36fc63a31383 100644 --- a/ext/uri/tests/013.phpt +++ b/ext/uri/tests/013.phpt @@ -5,17 +5,17 @@ uri --FILE-- + @")); +var_dump(Uri\Rfc3986Uri::parse("http://example.com?foobar=%27%3Cscript%3E+%2B+%40")); +var_dump(Uri\Rfc3986Uri::parse("http://example.com?foobar='