diff --git a/ext/lexbor/lexbor/url/url.c b/ext/lexbor/lexbor/url/url.c
index c88f8e7a7ad6..c9d5bd561c95 100644
--- a/ext/lexbor/lexbor/url/url.c
+++ b/ext/lexbor/lexbor/url/url.c
@@ -599,10 +599,6 @@ lxb_url_percent_decode(const lxb_char_t *data, const lxb_char_t *end,
lexbor_str_t *str, lexbor_mraw_t *mraw,
lxb_url_host_opt_t *opt);
-static lxb_status_t
-lxb_url_percent_decode_plus(const lxb_char_t *data, const lxb_char_t *end,
- lexbor_str_t *str, lexbor_mraw_t *mraw);
-
static const lxb_char_t *
lxb_url_path_part_by_index(const lxb_url_t *url, size_t index,
size_t *out_length);
@@ -4188,7 +4184,7 @@ lxb_url_percent_decode(const lxb_char_t *data, const lxb_char_t *end,
return LXB_STATUS_OK;
}
-static lxb_status_t
+lxb_status_t
lxb_url_percent_decode_plus(const lxb_char_t *data, const lxb_char_t *end,
lexbor_str_t *str, lexbor_mraw_t *mraw)
{
diff --git a/ext/lexbor/lexbor/url/url.h b/ext/lexbor/lexbor/url/url.h
index 5ecc1da5dfbc..fee9a05752f0 100644
--- a/ext/lexbor/lexbor/url/url.h
+++ b/ext/lexbor/lexbor/url/url.h
@@ -1025,6 +1025,10 @@ lxb_url_get(lxb_url_parser_t *parser)
return parser->url;
}
+lxb_status_t
+lxb_url_percent_decode_plus(const lxb_char_t *data, const lxb_char_t *end,
+ lexbor_str_t *str, lexbor_mraw_t *mraw);
+
#ifdef __cplusplus
} /* extern "C" */
diff --git a/ext/uri/config.m4 b/ext/uri/config.m4
index dddf0c6e00b8..463ab9766633 100644
--- a/ext/uri/config.m4
+++ b/ext/uri/config.m4
@@ -12,6 +12,7 @@ PHP_INSTALL_HEADERS([ext/uri], m4_normalize([
php_uri.h
php_uri_common.h
php_uri_decl.h
+ php_uri_query.h
uri_parser_rfc3986.h
uri_parser_whatwg.h
uri_parser_php_parse_url.h
@@ -39,7 +40,7 @@ else
PHP_EVAL_INCLINE([$LIBURIPARSER_CFLAGS])
fi
-PHP_NEW_EXTENSION(uri, [php_uri.c php_uri_common.c uri_parser_rfc3986.c uri_parser_whatwg.c uri_parser_php_parse_url.c $URIPARSER_SOURCES], [no],,[$URI_CFLAGS])
+PHP_NEW_EXTENSION(uri, [php_uri.c php_uri_common.c php_uri_query.c uri_parser_rfc3986.c uri_parser_whatwg.c uri_parser_php_parse_url.c $URIPARSER_SOURCES], [no],,[$URI_CFLAGS])
PHP_ADD_EXTENSION_DEP(uri, lexbor)
if test "$PHP_EXTERNAL_URIPARSER" = "no"; then
diff --git a/ext/uri/config.w32 b/ext/uri/config.w32
index 597ffb9fa03a..96b4a1f5971e 100644
--- a/ext/uri/config.w32
+++ b/ext/uri/config.w32
@@ -1,4 +1,4 @@
-EXTENSION("uri", "php_uri.c php_uri_common.c uri_parser_rfc3986.c uri_parser_whatwg.c uri_parser_php_parse_url.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include");
+EXTENSION("uri", "php_uri.c php_uri_common.c php_uri_query.c uri_parser_rfc3986.c uri_parser_whatwg.c uri_parser_php_parse_url.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include");
AC_DEFINE("URI_ENABLE_ANSI", 1, "Define to 1 for enabling ANSI support of uriparser.")
AC_DEFINE("URI_NO_UNICODE", 1, "Define to 1 for disabling unicode support of uriparser.")
@@ -9,4 +9,4 @@ ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriCopy.c UriEsca
UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriResolve.c \
UriSetFragment.c UriSetHostAuto.c UriSetHostCommon.c UriSetHostIp4.c UriSetHostIp6.c UriSetHostIpFuture.c UriSetHostRegName.c \
UriSetPath.c UriSetPort.c UriSetQuery.c UriSetScheme.c UriSetUserInfo.c UriShorten.c UriVersion.c", "uri");
-PHP_INSTALL_HEADERS("ext/uri", "php_uri.h php_uri_common.h php_uri_decl.h uri_parser_rfc3986.h uri_parser_whatwg.h uri_parser_php_parse_url.h uriparser/src uriparser/include");
+PHP_INSTALL_HEADERS("ext/uri", "php_uri.h php_uri_common.h php_uri_decl.h php_uri_query.h uri_parser_rfc3986.h uri_parser_whatwg.h uri_parser_php_parse_url.h uriparser/src uriparser/include");
diff --git a/ext/uri/php_uri.c b/ext/uri/php_uri.c
index 5f9a71a51d32..c08fbb8aad63 100644
--- a/ext/uri/php_uri.c
+++ b/ext/uri/php_uri.c
@@ -22,6 +22,7 @@
#include "ext/standard/info.h"
#include "php_uri.h"
+#include "php_uri_query.h"
#include "uri_parser_whatwg.h"
#include "uri_parser_rfc3986.h"
#include "uri_parser_php_parse_url.h"
@@ -39,6 +40,8 @@ zend_class_entry *php_uri_ce_comparison_mode;
zend_class_entry *php_uri_ce_exception;
zend_class_entry *php_uri_ce_error;
zend_class_entry *php_uri_ce_invalid_uri_exception;
+zend_class_entry *php_uri_ce_invalid_query_params_exception;
+zend_class_entry *php_uri_ce_query_params;
zend_class_entry *php_uri_ce_whatwg_url_host_type;
zend_class_entry *php_uri_ce_whatwg_invalid_url_exception;
zend_class_entry *php_uri_ce_whatwg_url_validation_error_type;
@@ -46,6 +49,7 @@ zend_class_entry *php_uri_ce_whatwg_url_validation_error;
static zend_object_handlers object_handlers_rfc3986_uri;
static zend_object_handlers object_handlers_whatwg_uri;
+static zend_object_handlers object_handlers_query_params;
typedef zend_result (*php_uri_component_validator_string)(const zend_string *component);
typedef zend_result (*php_uri_component_validator_long)(zend_long component);
@@ -704,6 +708,54 @@ PHP_METHOD(Uri_Rfc3986_Uri, getQuery)
php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII);
}
+static void uri_get_query_params(INTERNAL_FUNCTION_PARAMETERS, const php_uri_query_params_parsing_method parsing_method)
+{
+ zend_long max_param_count = PHP_URI_QUERY_PARAMS_DEFAULT_MAX_PARAM_COUNT;
+
+ ZEND_PARSE_PARAMETERS_START(0, 1)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(max_param_count)
+ ZEND_PARSE_PARAMETERS_END();
+
+ if (max_param_count < 0) {
+ zend_argument_value_error(1, "must be greater than or equal to 0");
+ RETURN_THROWS();
+ }
+
+ const php_uri_object *uri_object = Z_URI_OBJECT_P(ZEND_THIS);
+ ZEND_ASSERT(uri_object->uri != NULL);
+
+ zval query;
+ ZVAL_UNDEF(&query);
+
+ if (UNEXPECTED(uri_object->parser->property_handler.query.read(uri_object->uri, PHP_URI_COMPONENT_READ_MODE_RAW, &query) == FAILURE)) {
+ zval_ptr_dtor(&query);
+ zend_throw_exception_ex(php_uri_ce_error, 0, "The query component cannot be retrieved");
+ RETURN_THROWS();
+ }
+
+ if (Z_TYPE(query) == IS_NULL) {
+ RETURN_NULL();
+ }
+
+ object_init_ex(return_value, php_uri_ce_query_params);
+
+ const zend_result result = php_uri_query_params_parse(
+ Z_STRVAL(query), Z_STRLEN(query), Z_URI_QUERY_PARAMS_OBJECT_P(return_value),
+ parsing_method, false, max_param_count
+ );
+ zval_ptr_dtor(&query);
+
+ if (UNEXPECTED(result == FAILURE)) {
+ RETURN_THROWS();
+ }
+}
+
+PHP_METHOD(Uri_Rfc3986_Uri, getQueryParams)
+{
+ uri_get_query_params(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC3986);
+}
+
PHP_METHOD(Uri_Rfc3986_Uri, getRawQuery)
{
php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, PHP_URI_COMPONENT_READ_MODE_RAW);
@@ -714,6 +766,32 @@ PHP_METHOD(Uri_Rfc3986_Uri, withQuery)
php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY);
}
+PHP_METHOD(Uri_Rfc3986_Uri, withQueryParams)
+{
+ zend_object *query_params = NULL;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_OBJ_OF_CLASS_OR_NULL(query_params, php_uri_ce_query_params)
+ ZEND_PARSE_PARAMETERS_END();
+
+ zval zv;
+
+ if (query_params == NULL) {
+ ZVAL_NULL(&zv);
+ } else {
+ zend_string *query = php_uri_query_params_to_rfc3986_string(php_uri_query_params_object_from_obj(query_params));
+ /* This should be unreachable in practice, as query is null only due to memory errors. */
+ if (UNEXPECTED(query == NULL)) {
+ zend_throw_exception_ex(php_uri_ce_error, 0, "Cannot recompose %pS to a string", query_params->ce->name);
+ RETURN_THROWS();
+ }
+ ZVAL_STR(&zv, query);
+ }
+
+ php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, &zv);
+ zval_ptr_dtor(&zv);
+}
+
PHP_METHOD(Uri_Rfc3986_Uri, getFragment)
{
php_uri_property_read_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_FRAGMENT, PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII);
@@ -989,6 +1067,37 @@ PHP_METHOD(Uri_WhatWg_Url, getHostType)
php_uri_parser_whatwg_host_type_read(uri_object->uri, return_value);
}
+PHP_METHOD(Uri_WhatWg_Url, getQueryParams)
+{
+ uri_get_query_params(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL);
+}
+
+PHP_METHOD(Uri_WhatWg_Url, withQueryParams)
+{
+ zend_object *query_params = NULL;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_OBJ_OF_CLASS_OR_NULL(query_params, php_uri_ce_query_params)
+ ZEND_PARSE_PARAMETERS_END();
+
+ zval zv;
+
+ if (query_params == NULL) {
+ ZVAL_NULL(&zv);
+ } else {
+ zend_string *query = php_uri_query_params_to_whatwg_string(php_uri_query_params_object_from_obj(query_params));
+ /* This should be unreachable in practice, as query is null only due to memory errors. */
+ if (UNEXPECTED(query == NULL)) {
+ zend_throw_exception_ex(php_uri_ce_error, 0, "Cannot recompose %pS to a string", query_params->ce->name);
+ RETURN_THROWS();
+ }
+ ZVAL_STR(&zv, query);
+ }
+
+ php_uri_property_write_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_PROPERTY_NAME_QUERY, &zv);
+ zval_ptr_dtor(&zv);
+}
+
PHP_METHOD(Uri_WhatWg_Url, equals)
{
zend_object *that_object;
@@ -1537,6 +1646,19 @@ PHPAPI zend_result php_uri_parser_register(const php_uri_parser *uri_parser)
return result;
}
+static PHP_MINFO_FUNCTION(uri)
+{
+ php_info_print_table_start();
+ php_info_print_table_row(2, "URI support", "active");
+#ifdef URI_STATIC_BUILD
+ php_info_print_table_row(2, "uriparser bundled version", URI_VER_ANSI);
+#else
+ php_info_print_table_row(2, "uriparser compiled version", URI_VER_ANSI);
+ php_info_print_table_row(2, "uriparser loaded version", uriBaseRuntimeVersionA());
+#endif
+ php_info_print_table_end();
+}
+
static PHP_MINIT_FUNCTION(uri)
{
php_uri_ce_rfc3986_uri_builder = register_class_Uri_Rfc3986_UriBuilder();
@@ -1568,6 +1690,17 @@ static PHP_MINIT_FUNCTION(uri)
php_uri_ce_exception = register_class_Uri_UriException(zend_ce_exception);
php_uri_ce_error = register_class_Uri_UriError(zend_ce_error);
php_uri_ce_invalid_uri_exception = register_class_Uri_InvalidUriException(php_uri_ce_exception);
+ php_uri_ce_invalid_query_params_exception = register_class_Uri_InvalidQueryParamsException(php_uri_ce_exception);
+
+ php_uri_ce_query_params = register_class_Uri_QueryParams(zend_ce_aggregate, zend_ce_countable);
+ php_uri_ce_query_params->create_object = php_uri_object_query_params_create_object;
+ php_uri_ce_query_params->get_iterator = php_uri_object_query_params_get_iterator;
+ php_uri_ce_query_params->default_object_handlers = &object_handlers_query_params;
+ memcpy(&object_handlers_query_params, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ object_handlers_query_params.offset = offsetof(php_uri_query_params_object, std);
+ object_handlers_query_params.free_obj = php_uri_query_params_object_handler_free;
+ object_handlers_query_params.clone_obj = php_uri_query_params_object_handler_clone;
+
php_uri_ce_whatwg_invalid_url_exception = register_class_Uri_WhatWg_InvalidUrlException(php_uri_ce_invalid_uri_exception);
php_uri_ce_whatwg_url_host_type = register_class_Uri_WhatWg_UrlHostType();
php_uri_ce_whatwg_url_validation_error = register_class_Uri_WhatWg_UrlValidationError();
@@ -1590,19 +1723,6 @@ static PHP_MINIT_FUNCTION(uri)
return SUCCESS;
}
-static PHP_MINFO_FUNCTION(uri)
-{
- php_info_print_table_start();
- php_info_print_table_row(2, "URI support", "active");
-#ifdef URI_STATIC_BUILD
- php_info_print_table_row(2, "uriparser bundled version", URI_VER_ANSI);
-#else
- php_info_print_table_row(2, "uriparser compiled version", URI_VER_ANSI);
- php_info_print_table_row(2, "uriparser loaded version", uriBaseRuntimeVersionA());
-#endif
- php_info_print_table_end();
-}
-
static PHP_MSHUTDOWN_FUNCTION(uri)
{
zend_hash_destroy(&uri_parsers);
diff --git a/ext/uri/php_uri.stub.php b/ext/uri/php_uri.stub.php
index 856a960a732a..5004c19f05f9 100644
--- a/ext/uri/php_uri.stub.php
+++ b/ext/uri/php_uri.stub.php
@@ -21,11 +21,82 @@ class InvalidUriException extends \Uri\UriException
{
}
+ /** @strict-properties */
+ class InvalidQueryParamsException extends \Uri\UriException
+ {
+ }
+
enum UriComparisonMode
{
case IncludeFragment;
case ExcludeFragment;
}
+
+ /** @strict-properties */
+ final readonly class QueryParams implements \IteratorAggregate, \Countable
+ {
+ public static function parseRfc1866(string $queryString, int $maxParamCount = 1000): \Uri\QueryParams {}
+
+ public static function parseRfc3986(string $queryString, int $maxParamCount = 1000): \Uri\QueryParams {}
+
+ public static function parseWhatWgUrlSearchParams(string $queryString, int $maxParamCount = 1000): \Uri\QueryParams {}
+
+ public static function fromArray(array $queryParams): \Uri\QueryParams {}
+
+ public static function fromList(array $queryParams): \Uri\QueryParams {}
+
+ public function __construct() {}
+
+ public function has(string $name): bool {}
+
+ public function hasValue(string $name, string|int|float|\BackedEnum|null $value): bool {}
+
+ public function getFirst(string $name): ?string {}
+
+ public function getLast(string $name): ?string {}
+
+ public function getAll(string $name): array {}
+
+ public function getIterator(): \Traversable {}
+
+ public function count(): int {}
+
+ #[\NoDiscard]
+ public function append(string $name, string|int|float|\BackedEnum|null $value): static {}
+
+ #[\NoDiscard]
+ public function set(string $name, string|int|float|\BackedEnum|null $value): static {}
+
+ #[\NoDiscard]
+ public function delete(string $name): static {}
+
+ #[\NoDiscard]
+ public function deleteValue(string $name, string|int|float|\BackedEnum|null $value): static {}
+
+ #[\NoDiscard]
+ public function sortByBytes(): static {}
+
+ #[\NoDiscard]
+ public function sortByUtf16(): static {}
+
+ public function withArray(array $queryParams): static {}
+
+ public function toList(): array {}
+
+ public function toArray(int $maxNestingLevel = 64): array {}
+
+ public function toRfc1866String(): string {}
+
+ public function toRfc3986String(): string {}
+
+ public function toWhatWgUrlString(): string {}
+
+ public function __serialize(): array {}
+
+ public function __unserialize(array $data): void {}
+
+ public function __debugInfo(): array {}
+ }
}
namespace Uri\Rfc3986 {
@@ -126,8 +197,12 @@ public function getQuery(): ?string {}
public function getRawQuery(): ?string {}
+ public function getQueryParams(int $maxParamCount = 1000): ?\Uri\QueryParams {}
+
public function withQuery(?string $query): static {}
+ public function withQueryParams(?\Uri\QueryParams $queryParams): static {}
+
public function getFragment(): ?string {}
public function getRawFragment(): ?string {}
@@ -293,9 +368,13 @@ public function withPath(string $path): static {}
/** @implementation-alias Uri\Rfc3986\Uri::getQuery */
public function getQuery(): ?string {}
+ public function getQueryParams(int $maxParamCount = 1000): ?\Uri\QueryParams {}
+
/** @implementation-alias Uri\Rfc3986\Uri::withQuery */
public function withQuery(?string $query): static {}
+ public function withQueryParams(?\Uri\QueryParams $queryParams): static {}
+
/** @implementation-alias Uri\Rfc3986\Uri::getFragment */
public function getFragment(): ?string {}
diff --git a/ext/uri/php_uri_arginfo.h b/ext/uri/php_uri_arginfo.h
index 43535287d785..66b4e12a513e 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 php_uri.stub.php instead.
- * Stub hash: d96bdceccf7867b022c923bcfaf9f7a1142f0d0b
+ * Stub hash: ace84f735e326eee3eaeee710ac0a60ae0de3123
* Has decl header: yes */
#include "zend_attributes.h"
@@ -10,9 +10,95 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Uri_WhatWg_url_percent_encode, 0
ZEND_ARG_OBJ_INFO(0, mode, Uri\\WhatWg\\\125rlPercentEncodingMode, 0)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_UriBuilder_reset, 0, 0, IS_STATIC, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Uri_QueryParams_parseRfc1866, 0, 1, Uri\\QueryParams, 0)
+ ZEND_ARG_TYPE_INFO(0, queryString, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxParamCount, IS_LONG, 0, "1000")
ZEND_END_ARG_INFO()
+#define arginfo_class_Uri_QueryParams_parseRfc3986 arginfo_class_Uri_QueryParams_parseRfc1866
+
+#define arginfo_class_Uri_QueryParams_parseWhatWgUrlSearchParams arginfo_class_Uri_QueryParams_parseRfc1866
+
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Uri_QueryParams_fromArray, 0, 1, Uri\\QueryParams, 0)
+ ZEND_ARG_TYPE_INFO(0, queryParams, IS_ARRAY, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_Uri_QueryParams_fromList arginfo_class_Uri_QueryParams_fromArray
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Uri_QueryParams___construct, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_has, 0, 1, _IS_BOOL, 0)
+ ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_hasValue, 0, 2, _IS_BOOL, 0)
+ ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+ ZEND_ARG_OBJ_TYPE_MASK(0, value, BackedEnum, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_NULL, NULL)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_getFirst, 0, 1, IS_STRING, 1)
+ ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_Uri_QueryParams_getLast arginfo_class_Uri_QueryParams_getFirst
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_getAll, 0, 1, IS_ARRAY, 0)
+ ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Uri_QueryParams_getIterator, 0, 0, Traversable, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_count, 0, 0, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_append, 0, 2, IS_STATIC, 0)
+ ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+ ZEND_ARG_OBJ_TYPE_MASK(0, value, BackedEnum, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_NULL, NULL)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_Uri_QueryParams_set arginfo_class_Uri_QueryParams_append
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_delete, 0, 1, IS_STATIC, 0)
+ ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_Uri_QueryParams_deleteValue arginfo_class_Uri_QueryParams_append
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_sortByBytes, 0, 0, IS_STATIC, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_Uri_QueryParams_sortByUtf16 arginfo_class_Uri_QueryParams_sortByBytes
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_withArray, 0, 1, IS_STATIC, 0)
+ ZEND_ARG_TYPE_INFO(0, queryParams, IS_ARRAY, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_toList, 0, 0, IS_ARRAY, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_toArray, 0, 0, IS_ARRAY, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxNestingLevel, IS_LONG, 0, "64")
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams_toRfc1866String, 0, 0, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_Uri_QueryParams_toRfc3986String arginfo_class_Uri_QueryParams_toRfc1866String
+
+#define arginfo_class_Uri_QueryParams_toWhatWgUrlString arginfo_class_Uri_QueryParams_toRfc1866String
+
+#define arginfo_class_Uri_QueryParams___serialize arginfo_class_Uri_QueryParams_toList
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_QueryParams___unserialize, 0, 1, IS_VOID, 0)
+ ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_class_Uri_QueryParams___debugInfo arginfo_class_Uri_QueryParams_toList
+
+#define arginfo_class_Uri_Rfc3986_UriBuilder_reset arginfo_class_Uri_QueryParams_sortByBytes
+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_UriBuilder_setScheme, 0, 1, IS_STATIC, 0)
ZEND_ARG_TYPE_INFO(0, scheme, IS_STRING, 1)
ZEND_END_ARG_INFO()
@@ -95,10 +181,9 @@ ZEND_END_ARG_INFO()
#define arginfo_class_Uri_Rfc3986_Uri_withPort arginfo_class_Uri_Rfc3986_UriBuilder_setPort
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_Uri_getPath, 0, 0, IS_STRING, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_Uri_Rfc3986_Uri_getPath arginfo_class_Uri_QueryParams_toRfc1866String
-#define arginfo_class_Uri_Rfc3986_Uri_getRawPath arginfo_class_Uri_Rfc3986_Uri_getPath
+#define arginfo_class_Uri_Rfc3986_Uri_getRawPath arginfo_class_Uri_QueryParams_toRfc1866String
#define arginfo_class_Uri_Rfc3986_Uri_withPath arginfo_class_Uri_Rfc3986_UriBuilder_setPath
@@ -106,8 +191,16 @@ ZEND_END_ARG_INFO()
#define arginfo_class_Uri_Rfc3986_Uri_getRawQuery arginfo_class_Uri_Rfc3986_Uri_getScheme
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Uri_Rfc3986_Uri_getQueryParams, 0, 0, Uri\\QueryParams, 1)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, maxParamCount, IS_LONG, 0, "1000")
+ZEND_END_ARG_INFO()
+
#define arginfo_class_Uri_Rfc3986_Uri_withQuery arginfo_class_Uri_Rfc3986_UriBuilder_setQuery
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_Uri_withQueryParams, 0, 1, IS_STATIC, 0)
+ ZEND_ARG_OBJ_INFO(0, queryParams, Uri\\QueryParams, 1)
+ZEND_END_ARG_INFO()
+
#define arginfo_class_Uri_Rfc3986_Uri_getFragment arginfo_class_Uri_Rfc3986_Uri_getScheme
#define arginfo_class_Uri_Rfc3986_Uri_getRawFragment arginfo_class_Uri_Rfc3986_Uri_getScheme
@@ -119,22 +212,19 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_Uri_equals, 0,
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, comparisonMode, Uri\\\125riComparisonMode, 0, "Uri\\UriComparisonMode::ExcludeFragment")
ZEND_END_ARG_INFO()
-#define arginfo_class_Uri_Rfc3986_Uri_toString arginfo_class_Uri_Rfc3986_Uri_getPath
+#define arginfo_class_Uri_Rfc3986_Uri_toString arginfo_class_Uri_QueryParams_toRfc1866String
-#define arginfo_class_Uri_Rfc3986_Uri_toRawString arginfo_class_Uri_Rfc3986_Uri_getPath
+#define arginfo_class_Uri_Rfc3986_Uri_toRawString arginfo_class_Uri_QueryParams_toRfc1866String
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_Uri_resolve, 0, 1, IS_STATIC, 0)
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_Uri___serialize, 0, 0, IS_ARRAY, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_Uri_Rfc3986_Uri___serialize arginfo_class_Uri_QueryParams_toList
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_Rfc3986_Uri___unserialize, 0, 1, IS_VOID, 0)
- ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_Uri_Rfc3986_Uri___unserialize arginfo_class_Uri_QueryParams___unserialize
-#define arginfo_class_Uri_Rfc3986_Uri___debugInfo arginfo_class_Uri_Rfc3986_Uri___serialize
+#define arginfo_class_Uri_Rfc3986_Uri___debugInfo arginfo_class_Uri_QueryParams_toList
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Uri_WhatWg_InvalidUrlException___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, message, IS_STRING, 0, "\"\"")
@@ -149,7 +239,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Uri_WhatWg_UrlValidationError___construct,
ZEND_ARG_TYPE_INFO(0, failure, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
-#define arginfo_class_Uri_WhatWg_UrlBuilder_reset arginfo_class_Uri_Rfc3986_UriBuilder_reset
+#define arginfo_class_Uri_WhatWg_UrlBuilder_reset arginfo_class_Uri_QueryParams_sortByBytes
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_WhatWg_UrlBuilder_setScheme, 0, 1, IS_STATIC, 0)
ZEND_ARG_TYPE_INFO(0, scheme, IS_STRING, 0)
@@ -190,7 +280,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Uri_WhatWg_Url___construct, 0, 0, 1)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, softErrors, "null")
ZEND_END_ARG_INFO()
-#define arginfo_class_Uri_WhatWg_Url_getScheme arginfo_class_Uri_Rfc3986_Uri_getPath
+#define arginfo_class_Uri_WhatWg_Url_getScheme arginfo_class_Uri_QueryParams_toRfc1866String
#define arginfo_class_Uri_WhatWg_Url_withScheme arginfo_class_Uri_WhatWg_UrlBuilder_setScheme
@@ -218,14 +308,18 @@ ZEND_END_ARG_INFO()
#define arginfo_class_Uri_WhatWg_Url_withPort arginfo_class_Uri_Rfc3986_UriBuilder_setPort
-#define arginfo_class_Uri_WhatWg_Url_getPath arginfo_class_Uri_Rfc3986_Uri_getPath
+#define arginfo_class_Uri_WhatWg_Url_getPath arginfo_class_Uri_QueryParams_toRfc1866String
#define arginfo_class_Uri_WhatWg_Url_withPath arginfo_class_Uri_Rfc3986_UriBuilder_setPath
#define arginfo_class_Uri_WhatWg_Url_getQuery arginfo_class_Uri_Rfc3986_Uri_getScheme
+#define arginfo_class_Uri_WhatWg_Url_getQueryParams arginfo_class_Uri_Rfc3986_Uri_getQueryParams
+
#define arginfo_class_Uri_WhatWg_Url_withQuery arginfo_class_Uri_Rfc3986_UriBuilder_setQuery
+#define arginfo_class_Uri_WhatWg_Url_withQueryParams arginfo_class_Uri_Rfc3986_Uri_withQueryParams
+
#define arginfo_class_Uri_WhatWg_Url_getFragment arginfo_class_Uri_Rfc3986_Uri_getScheme
#define arginfo_class_Uri_WhatWg_Url_withFragment arginfo_class_Uri_Rfc3986_UriBuilder_setFragment
@@ -235,22 +329,50 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_WhatWg_Url_equals, 0,
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, comparisonMode, Uri\\\125riComparisonMode, 0, "Uri\\UriComparisonMode::ExcludeFragment")
ZEND_END_ARG_INFO()
-#define arginfo_class_Uri_WhatWg_Url_toAsciiString arginfo_class_Uri_Rfc3986_Uri_getPath
+#define arginfo_class_Uri_WhatWg_Url_toAsciiString arginfo_class_Uri_QueryParams_toRfc1866String
-#define arginfo_class_Uri_WhatWg_Url_toUnicodeString arginfo_class_Uri_Rfc3986_Uri_getPath
+#define arginfo_class_Uri_WhatWg_Url_toUnicodeString arginfo_class_Uri_QueryParams_toRfc1866String
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Uri_WhatWg_Url_resolve, 0, 1, IS_STATIC, 0)
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, softErrors, "null")
ZEND_END_ARG_INFO()
-#define arginfo_class_Uri_WhatWg_Url___serialize arginfo_class_Uri_Rfc3986_Uri___serialize
+#define arginfo_class_Uri_WhatWg_Url___serialize arginfo_class_Uri_QueryParams_toList
-#define arginfo_class_Uri_WhatWg_Url___unserialize arginfo_class_Uri_Rfc3986_Uri___unserialize
+#define arginfo_class_Uri_WhatWg_Url___unserialize arginfo_class_Uri_QueryParams___unserialize
-#define arginfo_class_Uri_WhatWg_Url___debugInfo arginfo_class_Uri_Rfc3986_Uri___serialize
+#define arginfo_class_Uri_WhatWg_Url___debugInfo arginfo_class_Uri_QueryParams_toList
ZEND_FUNCTION(Uri_WhatWg_url_percent_encode);
+ZEND_METHOD(Uri_QueryParams, parseRfc1866);
+ZEND_METHOD(Uri_QueryParams, parseRfc3986);
+ZEND_METHOD(Uri_QueryParams, parseWhatWgUrlSearchParams);
+ZEND_METHOD(Uri_QueryParams, fromArray);
+ZEND_METHOD(Uri_QueryParams, fromList);
+ZEND_METHOD(Uri_QueryParams, __construct);
+ZEND_METHOD(Uri_QueryParams, has);
+ZEND_METHOD(Uri_QueryParams, hasValue);
+ZEND_METHOD(Uri_QueryParams, getFirst);
+ZEND_METHOD(Uri_QueryParams, getLast);
+ZEND_METHOD(Uri_QueryParams, getAll);
+ZEND_METHOD(Uri_QueryParams, getIterator);
+ZEND_METHOD(Uri_QueryParams, count);
+ZEND_METHOD(Uri_QueryParams, append);
+ZEND_METHOD(Uri_QueryParams, set);
+ZEND_METHOD(Uri_QueryParams, delete);
+ZEND_METHOD(Uri_QueryParams, deleteValue);
+ZEND_METHOD(Uri_QueryParams, sortByBytes);
+ZEND_METHOD(Uri_QueryParams, sortByUtf16);
+ZEND_METHOD(Uri_QueryParams, withArray);
+ZEND_METHOD(Uri_QueryParams, toList);
+ZEND_METHOD(Uri_QueryParams, toArray);
+ZEND_METHOD(Uri_QueryParams, toRfc1866String);
+ZEND_METHOD(Uri_QueryParams, toRfc3986String);
+ZEND_METHOD(Uri_QueryParams, toWhatWgUrlString);
+ZEND_METHOD(Uri_QueryParams, __serialize);
+ZEND_METHOD(Uri_QueryParams, __unserialize);
+ZEND_METHOD(Uri_QueryParams, __debugInfo);
ZEND_METHOD(Uri_Rfc3986_UriBuilder, reset);
ZEND_METHOD(Uri_Rfc3986_UriBuilder, setScheme);
ZEND_METHOD(Uri_Rfc3986_UriBuilder, setUserInfo);
@@ -284,7 +406,9 @@ ZEND_METHOD(Uri_Rfc3986_Uri, getRawPath);
ZEND_METHOD(Uri_Rfc3986_Uri, withPath);
ZEND_METHOD(Uri_Rfc3986_Uri, getQuery);
ZEND_METHOD(Uri_Rfc3986_Uri, getRawQuery);
+ZEND_METHOD(Uri_Rfc3986_Uri, getQueryParams);
ZEND_METHOD(Uri_Rfc3986_Uri, withQuery);
+ZEND_METHOD(Uri_Rfc3986_Uri, withQueryParams);
ZEND_METHOD(Uri_Rfc3986_Uri, getFragment);
ZEND_METHOD(Uri_Rfc3986_Uri, getRawFragment);
ZEND_METHOD(Uri_Rfc3986_Uri, withFragment);
@@ -317,6 +441,8 @@ ZEND_METHOD(Uri_WhatWg_Url, withPassword);
ZEND_METHOD(Uri_WhatWg_Url, getAsciiHost);
ZEND_METHOD(Uri_WhatWg_Url, getUnicodeHost);
ZEND_METHOD(Uri_WhatWg_Url, getHostType);
+ZEND_METHOD(Uri_WhatWg_Url, getQueryParams);
+ZEND_METHOD(Uri_WhatWg_Url, withQueryParams);
ZEND_METHOD(Uri_WhatWg_Url, equals);
ZEND_METHOD(Uri_WhatWg_Url, toAsciiString);
ZEND_METHOD(Uri_WhatWg_Url, toUnicodeString);
@@ -330,6 +456,38 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE_END
};
+static const zend_function_entry class_Uri_QueryParams_methods[] = {
+ ZEND_ME(Uri_QueryParams, parseRfc1866, arginfo_class_Uri_QueryParams_parseRfc1866, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ ZEND_ME(Uri_QueryParams, parseRfc3986, arginfo_class_Uri_QueryParams_parseRfc3986, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ ZEND_ME(Uri_QueryParams, parseWhatWgUrlSearchParams, arginfo_class_Uri_QueryParams_parseWhatWgUrlSearchParams, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ ZEND_ME(Uri_QueryParams, fromArray, arginfo_class_Uri_QueryParams_fromArray, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ ZEND_ME(Uri_QueryParams, fromList, arginfo_class_Uri_QueryParams_fromList, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ ZEND_ME(Uri_QueryParams, __construct, arginfo_class_Uri_QueryParams___construct, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, has, arginfo_class_Uri_QueryParams_has, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, hasValue, arginfo_class_Uri_QueryParams_hasValue, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, getFirst, arginfo_class_Uri_QueryParams_getFirst, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, getLast, arginfo_class_Uri_QueryParams_getLast, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, getAll, arginfo_class_Uri_QueryParams_getAll, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, getIterator, arginfo_class_Uri_QueryParams_getIterator, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, count, arginfo_class_Uri_QueryParams_count, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, append, arginfo_class_Uri_QueryParams_append, ZEND_ACC_PUBLIC|ZEND_ACC_NODISCARD)
+ ZEND_ME(Uri_QueryParams, set, arginfo_class_Uri_QueryParams_set, ZEND_ACC_PUBLIC|ZEND_ACC_NODISCARD)
+ ZEND_ME(Uri_QueryParams, delete, arginfo_class_Uri_QueryParams_delete, ZEND_ACC_PUBLIC|ZEND_ACC_NODISCARD)
+ ZEND_ME(Uri_QueryParams, deleteValue, arginfo_class_Uri_QueryParams_deleteValue, ZEND_ACC_PUBLIC|ZEND_ACC_NODISCARD)
+ ZEND_ME(Uri_QueryParams, sortByBytes, arginfo_class_Uri_QueryParams_sortByBytes, ZEND_ACC_PUBLIC|ZEND_ACC_NODISCARD)
+ ZEND_ME(Uri_QueryParams, sortByUtf16, arginfo_class_Uri_QueryParams_sortByUtf16, ZEND_ACC_PUBLIC|ZEND_ACC_NODISCARD)
+ ZEND_ME(Uri_QueryParams, withArray, arginfo_class_Uri_QueryParams_withArray, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, toList, arginfo_class_Uri_QueryParams_toList, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, toArray, arginfo_class_Uri_QueryParams_toArray, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, toRfc1866String, arginfo_class_Uri_QueryParams_toRfc1866String, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, toRfc3986String, arginfo_class_Uri_QueryParams_toRfc3986String, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, toWhatWgUrlString, arginfo_class_Uri_QueryParams_toWhatWgUrlString, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, __serialize, arginfo_class_Uri_QueryParams___serialize, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, __unserialize, arginfo_class_Uri_QueryParams___unserialize, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_QueryParams, __debugInfo, arginfo_class_Uri_QueryParams___debugInfo, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
static const zend_function_entry class_Uri_Rfc3986_UriBuilder_methods[] = {
ZEND_ME(Uri_Rfc3986_UriBuilder, reset, arginfo_class_Uri_Rfc3986_UriBuilder_reset, ZEND_ACC_PUBLIC)
ZEND_ME(Uri_Rfc3986_UriBuilder, setScheme, arginfo_class_Uri_Rfc3986_UriBuilder_setScheme, ZEND_ACC_PUBLIC)
@@ -368,7 +526,9 @@ static const zend_function_entry class_Uri_Rfc3986_Uri_methods[] = {
ZEND_ME(Uri_Rfc3986_Uri, withPath, arginfo_class_Uri_Rfc3986_Uri_withPath, ZEND_ACC_PUBLIC)
ZEND_ME(Uri_Rfc3986_Uri, getQuery, arginfo_class_Uri_Rfc3986_Uri_getQuery, ZEND_ACC_PUBLIC)
ZEND_ME(Uri_Rfc3986_Uri, getRawQuery, arginfo_class_Uri_Rfc3986_Uri_getRawQuery, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_Rfc3986_Uri, getQueryParams, arginfo_class_Uri_Rfc3986_Uri_getQueryParams, ZEND_ACC_PUBLIC)
ZEND_ME(Uri_Rfc3986_Uri, withQuery, arginfo_class_Uri_Rfc3986_Uri_withQuery, ZEND_ACC_PUBLIC)
+ ZEND_ME(Uri_Rfc3986_Uri, withQueryParams, arginfo_class_Uri_Rfc3986_Uri_withQueryParams, ZEND_ACC_PUBLIC)
ZEND_ME(Uri_Rfc3986_Uri, getFragment, arginfo_class_Uri_Rfc3986_Uri_getFragment, ZEND_ACC_PUBLIC)
ZEND_ME(Uri_Rfc3986_Uri, getRawFragment, arginfo_class_Uri_Rfc3986_Uri_getRawFragment, ZEND_ACC_PUBLIC)
ZEND_ME(Uri_Rfc3986_Uri, withFragment, arginfo_class_Uri_Rfc3986_Uri_withFragment, ZEND_ACC_PUBLIC)
@@ -425,7 +585,9 @@ static const zend_function_entry class_Uri_WhatWg_Url_methods[] = {
ZEND_RAW_FENTRY("getPath", zim_Uri_Rfc3986_Uri_getPath, arginfo_class_Uri_WhatWg_Url_getPath, ZEND_ACC_PUBLIC, NULL, NULL)
ZEND_RAW_FENTRY("withPath", zim_Uri_Rfc3986_Uri_withPath, arginfo_class_Uri_WhatWg_Url_withPath, ZEND_ACC_PUBLIC, NULL, NULL)
ZEND_RAW_FENTRY("getQuery", zim_Uri_Rfc3986_Uri_getQuery, arginfo_class_Uri_WhatWg_Url_getQuery, ZEND_ACC_PUBLIC, NULL, NULL)
+ ZEND_ME(Uri_WhatWg_Url, getQueryParams, arginfo_class_Uri_WhatWg_Url_getQueryParams, ZEND_ACC_PUBLIC)
ZEND_RAW_FENTRY("withQuery", zim_Uri_Rfc3986_Uri_withQuery, arginfo_class_Uri_WhatWg_Url_withQuery, ZEND_ACC_PUBLIC, NULL, NULL)
+ ZEND_ME(Uri_WhatWg_Url, withQueryParams, arginfo_class_Uri_WhatWg_Url_withQueryParams, ZEND_ACC_PUBLIC)
ZEND_RAW_FENTRY("getFragment", zim_Uri_Rfc3986_Uri_getFragment, arginfo_class_Uri_WhatWg_Url_getFragment, ZEND_ACC_PUBLIC, NULL, NULL)
ZEND_RAW_FENTRY("withFragment", zim_Uri_Rfc3986_Uri_withFragment, arginfo_class_Uri_WhatWg_Url_withFragment, ZEND_ACC_PUBLIC, NULL, NULL)
ZEND_ME(Uri_WhatWg_Url, equals, arginfo_class_Uri_WhatWg_Url_equals, ZEND_ACC_PUBLIC)
@@ -468,6 +630,16 @@ static zend_class_entry *register_class_Uri_InvalidUriException(zend_class_entry
return class_entry;
}
+static zend_class_entry *register_class_Uri_InvalidQueryParamsException(zend_class_entry *class_entry_Uri_UriException)
+{
+ zend_class_entry ce, *class_entry;
+
+ INIT_NS_CLASS_ENTRY(ce, "Uri", "InvalidQueryParamsException", NULL);
+ class_entry = zend_register_internal_class_with_flags(&ce, class_entry_Uri_UriException, ZEND_ACC_NO_DYNAMIC_PROPERTIES);
+
+ return class_entry;
+}
+
static zend_class_entry *register_class_Uri_UriComparisonMode(void)
{
zend_class_entry *class_entry = zend_register_internal_enum("Uri\\UriComparisonMode", IS_UNDEF, NULL);
@@ -479,6 +651,30 @@ static zend_class_entry *register_class_Uri_UriComparisonMode(void)
return class_entry;
}
+static zend_class_entry *register_class_Uri_QueryParams(zend_class_entry *class_entry_IteratorAggregate, zend_class_entry *class_entry_Countable)
+{
+ zend_class_entry ce, *class_entry;
+
+ INIT_NS_CLASS_ENTRY(ce, "Uri", "QueryParams", class_Uri_QueryParams_methods);
+ class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_READONLY_CLASS);
+ zend_class_implements(class_entry, 2, class_entry_IteratorAggregate, class_entry_Countable);
+
+
+ zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "append", sizeof("append") - 1), ZSTR_KNOWN(ZEND_STR_NODISCARD), 0);
+
+ zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "set", sizeof("set") - 1), ZSTR_KNOWN(ZEND_STR_NODISCARD), 0);
+
+ zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "delete", sizeof("delete") - 1), ZSTR_KNOWN(ZEND_STR_NODISCARD), 0);
+
+ zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "deletevalue", sizeof("deletevalue") - 1), ZSTR_KNOWN(ZEND_STR_NODISCARD), 0);
+
+ zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "sortbybytes", sizeof("sortbybytes") - 1), ZSTR_KNOWN(ZEND_STR_NODISCARD), 0);
+
+ zend_add_function_attribute(zend_hash_str_find_ptr(&class_entry->function_table, "sortbyutf16", sizeof("sortbyutf16") - 1), ZSTR_KNOWN(ZEND_STR_NODISCARD), 0);
+
+ return class_entry;
+}
+
static zend_class_entry *register_class_Uri_Rfc3986_UriType(void)
{
zend_class_entry *class_entry = zend_register_internal_enum("Uri\\Rfc3986\\UriType", IS_UNDEF, NULL);
diff --git a/ext/uri/php_uri_common.c b/ext/uri/php_uri_common.c
index 34906ee89c62..0cc738c140f1 100644
--- a/ext/uri/php_uri_common.c
+++ b/ext/uri/php_uri_common.c
@@ -77,7 +77,7 @@ void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property
}
}
-static void php_uri_property_write_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, const zval *property_zv)
+void php_uri_property_write_helper(INTERNAL_FUNCTION_PARAMETERS, const php_uri_property_name property_name, const zval *property_zv)
{
php_uri_object *old_uri_object = Z_URI_OBJECT_P(ZEND_THIS);
ZEND_ASSERT(old_uri_object->uri != NULL);
diff --git a/ext/uri/php_uri_common.h b/ext/uri/php_uri_common.h
index a125ef17d1c4..627fcd04d81e 100644
--- a/ext/uri/php_uri_common.h
+++ b/ext/uri/php_uri_common.h
@@ -28,6 +28,8 @@ extern zend_class_entry *php_uri_ce_comparison_mode;
extern zend_class_entry *php_uri_ce_exception;
extern zend_class_entry *php_uri_ce_error;
extern zend_class_entry *php_uri_ce_invalid_uri_exception;
+extern zend_class_entry *php_uri_ce_invalid_query_params_exception;
+extern zend_class_entry *php_uri_ce_query_params;
extern zend_class_entry *php_uri_ce_whatwg_invalid_url_exception;
extern zend_class_entry *php_uri_ce_whatwg_url_validation_error_type;
extern zend_class_entry *php_uri_ce_whatwg_url_validation_error;
@@ -164,6 +166,7 @@ PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object);
#define PHP_URI_PARSER_WHATWG "Uri\\WhatWg\\Url"
#define PHP_URI_PARSER_PHP_PARSE_URL "parse_url"
#define PHP_URI_SERIALIZE_URI_FIELD_NAME "uri"
+#define PHP_URI_SERIALIZE_QUERY_PARAMS_FIELD_NAME "params"
static inline const php_uri_property_handler *php_uri_parser_property_handler_by_name(const php_uri_parser *parser, php_uri_property_name property_name)
{
@@ -190,8 +193,28 @@ static inline const php_uri_property_handler *php_uri_parser_property_handler_by
ZEND_ATTRIBUTE_NONNULL_ARGS(2) zend_result php_uri_pass_errors_by_ref_and_free(zval *errors_zv, HashTable *errors);
void php_uri_property_read_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, php_uri_component_read_mode component_read_mode);
+void php_uri_property_write_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name, const zval *property_zv);
void php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
void php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
void php_uri_property_write_long_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_property_name property_name);
+typedef struct php_uri_query_param_list_entry {
+ zend_string *key;
+ zend_string *value;
+ uint32_t next_index;
+} php_uri_query_param_list_entry;
+
+typedef struct php_uri_query_param_lookup_entry {
+ uint32_t first_index;
+ uint32_t last_index;
+} php_uri_query_param_lookup_entry;
+
+typedef struct php_uri_query_params_object {
+ HashTable entry_list;
+ HashTable entry_lookup_table;
+ uint32_t tombstone_count;
+ bool is_initialized;
+ zend_object std;
+} php_uri_query_params_object;
+
#endif
diff --git a/ext/uri/php_uri_decl.h b/ext/uri/php_uri_decl.h
index 9423aff69fe7..fc0107595097 100644
--- a/ext/uri/php_uri_decl.h
+++ b/ext/uri/php_uri_decl.h
@@ -1,8 +1,8 @@
/* This is a generated file, edit php_uri.stub.php instead.
- * Stub hash: d96bdceccf7867b022c923bcfaf9f7a1142f0d0b */
+ * Stub hash: ace84f735e326eee3eaeee710ac0a60ae0de3123 */
-#ifndef ZEND_PHP_URI_DECL_d96bdceccf7867b022c923bcfaf9f7a1142f0d0b_H
-#define ZEND_PHP_URI_DECL_d96bdceccf7867b022c923bcfaf9f7a1142f0d0b_H
+#ifndef ZEND_PHP_URI_DECL_ace84f735e326eee3eaeee710ac0a60ae0de3123_H
+#define ZEND_PHP_URI_DECL_ace84f735e326eee3eaeee710ac0a60ae0de3123_H
typedef enum zend_enum_Uri_UriComparisonMode {
ZEND_ENUM_Uri_UriComparisonMode_IncludeFragment = 1,
@@ -76,4 +76,4 @@ typedef enum zend_enum_Uri_WhatWg_UrlPercentEncodingMode {
ZEND_ENUM_Uri_WhatWg_UrlPercentEncodingMode_Fragment = 10,
} zend_enum_Uri_WhatWg_UrlPercentEncodingMode;
-#endif /* ZEND_PHP_URI_DECL_d96bdceccf7867b022c923bcfaf9f7a1142f0d0b_H */
+#endif /* ZEND_PHP_URI_DECL_ace84f735e326eee3eaeee710ac0a60ae0de3123_H */
diff --git a/ext/uri/php_uri_query.c b/ext/uri/php_uri_query.c
new file mode 100644
index 000000000000..d05e4818ab2f
--- /dev/null
+++ b/ext/uri/php_uri_query.c
@@ -0,0 +1,1752 @@
+/*
+ +----------------------------------------------------------------------+
+ | Copyright © The PHP Group and Contributors. |
+ +----------------------------------------------------------------------+
+ | This source file is subject to the Modified BSD License that is |
+ | bundled with this package in the file LICENSE, and is available |
+ | through the World Wide Web at . |
+ | |
+ | SPDX-License-Identifier: BSD-3-Clause |
+ +----------------------------------------------------------------------+
+ | Authors: Máté Kocsis |
+ +----------------------------------------------------------------------+
+*/
+#include "zend_enum.h"
+#include "zend_smart_str.h"
+#include "zend_API.h"
+#include "zend_hash.h"
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "php.h"
+#include "Zend/zend_exceptions.h"
+#include "Zend/zend_interfaces.h"
+
+#include "php_uri_common.h"
+#include "php_uri_query.h"
+#include "uri_parser_rfc3986.h"
+#include "uri_parser_whatwg.h"
+#include "lexbor/encoding/decode.h"
+
+#define MAX_TOMBSTONES 100
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1) static zend_string *php_uri_query_params_convert_value_to_str(
+ const zval *value, const zend_string *array_key
+) {
+ ZVAL_DEREF(value);
+
+ switch (Z_TYPE_P(value)) {
+ case IS_NULL:
+ return NULL;
+ case IS_DOUBLE: {
+ if (UNEXPECTED(!zend_finite(Z_DVAL_P(value)))) {
+ if (array_key != NULL) {
+ zend_argument_value_error(1,
+ "contains a non-finite float for query parameter \"%pS\"", array_key);
+ } else {
+ zend_argument_value_error(2, "must be finite");
+ }
+ return NULL;
+ }
+
+ char buffer[ZEND_DOUBLE_MAX_LENGTH];
+ zend_gcvt(Z_DVAL_P(value), (int) PG(serialize_precision), '.', 'e', buffer);
+ return zend_string_init(buffer, strlen(buffer), false);
+ }
+ case IS_OBJECT:
+ if (instanceof_function(Z_OBJCE_P(value), zend_ce_backed_enum)) {
+ value = zend_enum_fetch_case_value(Z_OBJ_P(value));
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (array_key != NULL) {
+ if (Z_TYPE_P(value) == IS_STRING || Z_TYPE_P(value) == IS_LONG || Z_TYPE_P(value) == IS_DOUBLE) {
+ return zval_get_string(value);
+ }
+ zend_argument_type_error(1,
+ "contains an invalid value for query parameter \"%pS\": expected BackedEnum|string|int|float|null, %s given",
+ array_key, zend_zval_value_name(value));
+ return NULL;
+ }
+
+ zval tmp;
+ ZVAL_COPY(&tmp, value);
+ zval *normalized;
+ zend_string *result = NULL;
+
+ if (zend_parse_arg_number_or_str(&tmp, &normalized, false, 2) && !EG(exception)) {
+ result = zval_get_string(&tmp);
+ } else if (!EG(exception)) {
+ zend_argument_type_error(2, "must be of type BackedEnum|string|int|float|null, %s given", zend_zval_value_name(&tmp));
+ }
+ zval_ptr_dtor(&tmp);
+
+ return result;
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) static bool php_uri_query_params_has_entry(
+ const php_uri_query_params_object *query_params_object, zend_string *name
+) {
+ const php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+
+ return lookup_entry != NULL;
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) static bool php_uri_query_params_has_entry_with_value(
+ const php_uri_query_params_object *query_params_object, zend_string *name, const zend_string *value
+) {
+ const php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+ if (lookup_entry == NULL) {
+ return false;
+ }
+
+ uint32_t index = lookup_entry->first_index;
+ while (index != UINT32_MAX) {
+ const php_uri_query_param_list_entry *list_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, index);
+ ZEND_ASSERT(list_entry != NULL);
+
+ if (
+ (value == NULL && list_entry->value == NULL) ||
+ (value != NULL && list_entry->value != NULL && zend_string_equal_content(value, list_entry->value))
+ ) {
+ return true;
+ }
+
+ index = list_entry->next_index;
+ }
+
+ return false;
+}
+
+static void php_uri_query_params_find_value(
+ const php_uri_query_params_object *query_params_object, const uint32_t index, zval *zv
+) {
+ const php_uri_query_param_list_entry *list_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, index);
+ ZEND_ASSERT(list_entry != NULL);
+
+ if (list_entry->value == NULL) {
+ ZVAL_NULL(zv);
+ } else {
+ ZVAL_STR_COPY(zv, list_entry->value);
+ }
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) static void php_uri_query_params_find_first_value(
+ const php_uri_query_params_object *query_params_object, zend_string *name, zval *zv
+) {
+ const php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+ if (lookup_entry == NULL) {
+ ZVAL_NULL(zv);
+ return;
+ }
+
+ php_uri_query_params_find_value(query_params_object, lookup_entry->first_index, zv);
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) static void php_uri_query_params_find_last_value(
+ const php_uri_query_params_object *query_params_object, zend_string *name, zval *zv
+) {
+ const php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+ if (lookup_entry == NULL) {
+ ZVAL_NULL(zv);
+ return;
+ }
+
+ php_uri_query_params_find_value(query_params_object, lookup_entry->last_index, zv);
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) static void php_uri_query_params_find_all_values(
+ const php_uri_query_params_object *query_params_object, zend_string *name, zval *zv
+) {
+ const php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+ if (lookup_entry == NULL) {
+ ZVAL_EMPTY_ARRAY(zv);
+ return;
+ }
+
+ array_init(zv);
+
+ uint32_t index = lookup_entry->first_index;
+ while (index != UINT32_MAX) {
+ const php_uri_query_param_list_entry *list_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, index);
+ ZEND_ASSERT(list_entry != NULL);
+
+ if (list_entry->key != NULL) {
+ zval value;
+ if (list_entry->value == NULL) {
+ ZVAL_NULL(&value);
+ } else {
+ ZVAL_STR_COPY(&value, list_entry->value);
+ }
+ zend_hash_next_index_insert(Z_ARR_P(zv), &value);
+ }
+
+ index = list_entry->next_index;
+ }
+}
+
+ZEND_ATTRIBUTE_NONNULL static void php_uri_query_params_list_entries(php_uri_query_params_object *object, zval *params)
+{
+ array_init_size(params, zend_array_count(&object->entry_list));
+
+ ZEND_HASH_FOREACH_PTR(&object->entry_list, php_uri_query_param_list_entry *list_entry) {
+ if (list_entry->key != NULL) {
+ zval key;
+ ZVAL_STR_COPY(&key, list_entry->key);
+
+ zval value;
+ if (list_entry->value == NULL) {
+ ZVAL_NULL(&value);
+ } else {
+ ZVAL_STR_COPY(&value, list_entry->value);
+ }
+
+ zval zv;
+ array_init_size(&zv, 2);
+ zend_hash_index_add(Z_ARR(zv), 0, &key);
+ zend_hash_index_add(Z_ARR(zv), 1, &value);
+
+ zend_hash_next_index_insert(Z_ARR_P(params), &zv);
+ }
+ } ZEND_HASH_FOREACH_END();
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) static zend_result php_uri_query_params_append_entry(
+ php_uri_query_params_object *query_params_object, zend_string *name, zend_string *value
+) {
+ php_uri_query_param_list_entry new_list_entry = {
+ .key = zend_string_copy(name),
+ .value = value == NULL ? NULL : zend_string_copy(value),
+ .next_index = UINT32_MAX,
+ };
+
+ const void *result = zend_hash_next_index_insert_mem(&query_params_object->entry_list, &new_list_entry, sizeof(new_list_entry));
+ if (result == NULL) {
+ return FAILURE;
+ }
+
+ const zend_long new_index = query_params_object->entry_list.nNextFreeElement - 1;
+
+ php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+
+ if (lookup_entry == NULL) {
+ /* Insert a new lookup entry */
+
+ php_uri_query_param_lookup_entry new_lookup_entry = {
+ .first_index = new_index,
+ .last_index = new_index,
+ };
+ if (zend_hash_add_mem(&query_params_object->entry_lookup_table, name, &new_lookup_entry, sizeof(new_lookup_entry)) == NULL) {
+ zend_hash_index_del(&query_params_object->entry_list, new_index);
+ return FAILURE;
+ }
+ } else {
+ /* Update the existing lookup entry + the same key list */
+
+ php_uri_query_param_list_entry *last_list_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, lookup_entry->last_index);
+ ZEND_ASSERT(last_list_entry != NULL);
+
+ last_list_entry->next_index = new_index;
+ lookup_entry->last_index = new_index;
+ }
+
+ return SUCCESS;
+}
+
+ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_query_params_append_array_value(
+ php_uri_query_params_object *object, zend_string *name, const zval *value
+) {
+ zend_result result = FAILURE;
+
+ zend_string *value_str = php_uri_query_params_convert_value_to_str(value, name);
+ if (!EG(exception)) {
+ result = php_uri_query_params_append_entry(object, name, value_str);
+ if (UNEXPECTED(result == FAILURE)) {
+ /* This should be unreachable in practice. */
+ zend_throw_exception(php_uri_ce_error, "Failed to append the query parameter", 0);
+ }
+ }
+
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+
+ return result;
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) static zend_result php_uri_query_params_append_array(
+ php_uri_query_params_object *object, HashTable *array, const zend_string *prefix
+) {
+ if (GC_IS_RECURSIVE(array)) {
+ zend_argument_value_error(1, "must not contain recursive arrays");
+ return FAILURE;
+ }
+
+#ifdef ZEND_CHECK_STACK_LIMIT
+ if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) {
+ zend_throw_error(NULL, "Maximum call stack size reached.");
+ return FAILURE;
+ }
+#endif
+
+ bool use_empty_brackets = prefix != NULL && zend_array_is_list(array);
+ if (use_empty_brackets) {
+ ZEND_HASH_FOREACH_VAL(array, zval *value) {
+ ZVAL_DEREF(value);
+ if (Z_TYPE_P(value) == IS_ARRAY) {
+ use_empty_brackets = false;
+ break;
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+
+ zend_result result = SUCCESS;
+ zend_ulong index;
+ zend_string *key;
+ zval *value;
+
+ GC_TRY_PROTECT_RECURSION(array);
+
+ ZEND_HASH_FOREACH_KEY_VAL(array, index, key, value) {
+ ZVAL_DEREF(value);
+
+ if (Z_TYPE_P(value) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(value)) == 0) {
+ continue;
+ }
+
+ zend_string *name;
+ if (prefix == NULL) {
+ name = key != NULL ? zend_string_copy(key) : zend_long_to_str((zend_long) index);
+ } else if (use_empty_brackets) {
+ name = zend_string_concat2(ZSTR_VAL(prefix), ZSTR_LEN(prefix), "[]", 2);
+ } else {
+ smart_str buf = {0};
+ smart_str_append(&buf, prefix);
+ smart_str_appendc(&buf, '[');
+ if (key != NULL) {
+ smart_str_append(&buf, key);
+ } else {
+ smart_str_append_long(&buf, (zend_long) index);
+ }
+ smart_str_appendc(&buf, ']');
+ name = smart_str_extract(&buf);
+ }
+
+ if (Z_TYPE_P(value) == IS_ARRAY) {
+ result = php_uri_query_params_append_array(object, Z_ARRVAL_P(value), name);
+ } else {
+ result = php_uri_query_params_append_array_value(object, name, value);
+ }
+
+ zend_string_release(name);
+ if (result == FAILURE) {
+ break;
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ GC_TRY_UNPROTECT_RECURSION(array);
+
+ return result;
+}
+
+ZEND_ATTRIBUTE_NONNULL static void php_uri_query_params_rebuild_lookup(const HashTable *entry_list, const HashTable *entry_lookup_table)
+{
+ ZEND_HASH_FOREACH_PTR(entry_lookup_table, php_uri_query_param_lookup_entry *lookup_entry) {
+ lookup_entry->first_index = UINT32_MAX;
+ lookup_entry->last_index = UINT32_MAX;
+ } ZEND_HASH_FOREACH_END();
+
+ zend_ulong new_index;
+ ZEND_HASH_FOREACH_NUM_KEY_PTR(entry_list, new_index, php_uri_query_param_list_entry *new_entry) {
+ new_entry->next_index = UINT32_MAX;
+ php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(entry_lookup_table, new_entry->key);
+ ZEND_ASSERT(lookup_entry != NULL);
+ if (lookup_entry->first_index == UINT32_MAX) {
+ lookup_entry->first_index = new_index;
+ } else {
+ php_uri_query_param_list_entry *prev_entry = zend_hash_index_find_ptr(entry_list, lookup_entry->last_index);
+ ZEND_ASSERT(prev_entry != NULL);
+ prev_entry->next_index = new_index;
+ }
+
+ lookup_entry->last_index = new_index;
+ } ZEND_HASH_FOREACH_END();
+}
+
+static int php_uri_query_params_remove_tombstone(zval *zv)
+{
+ const php_uri_query_param_list_entry *entry = Z_PTR_P(zv);
+
+ return entry->key == NULL ? ZEND_HASH_APPLY_REMOVE : ZEND_HASH_APPLY_KEEP;
+}
+
+ZEND_ATTRIBUTE_NONNULL static void php_uri_query_params_remove_tombstones(php_uri_query_params_object *object)
+{
+ if (object->tombstone_count == zend_hash_num_elements(&object->entry_list)) {
+ /* Reset the next insertion index when no live entries remain. */
+ zend_hash_clean(&object->entry_list);
+ } else {
+ zend_hash_apply(&object->entry_list, php_uri_query_params_remove_tombstone);
+ }
+ object->tombstone_count = 0;
+}
+
+ZEND_ATTRIBUTE_NONNULL static void php_uri_query_params_cleanup_tombstones(
+php_uri_query_params_object *query_params_object
+) {
+ if (query_params_object->tombstone_count <= MAX_TOMBSTONES) {
+ return;
+ }
+
+ HashTable *entry_list = &query_params_object->entry_list;
+ ZEND_ASSERT(HT_IS_PACKED(entry_list));
+ ZEND_ASSERT(!HT_HAS_ITERATORS(entry_list));
+
+ php_uri_query_params_remove_tombstones(query_params_object);
+
+ /* Get rid of any holes - ZEND_HASH_PACKED_FOREACH_VAL skips UNDEF items */
+ uint32_t new_index = 0;
+ ZEND_HASH_PACKED_FOREACH_VAL(entry_list, zval *entry_zv) {
+ zval *new_entry_zv = &entry_list->arPacked[new_index];
+ if (new_entry_zv != entry_zv) {
+ ZVAL_COPY_VALUE(new_entry_zv, entry_zv);
+ ZVAL_UNDEF(entry_zv);
+ }
+ new_index++;
+ } ZEND_HASH_FOREACH_END();
+
+ entry_list->nNumUsed = new_index;
+ entry_list->nNextFreeElement = new_index;
+ entry_list->nInternalPointer = 0;
+
+ php_uri_query_params_rebuild_lookup(entry_list, &query_params_object->entry_lookup_table);
+}
+
+static int php_uri_query_params_compare_original_order(const Bucket *a, const Bucket *b)
+{
+ /* zend_hash_sort() stores the original position in Z_EXTRA() for stable sorting. */
+ return (Z_EXTRA(a->val) > Z_EXTRA(b->val)) - (Z_EXTRA(a->val) < Z_EXTRA(b->val));
+}
+
+static int php_uri_query_params_compare_bytes(Bucket *a, Bucket *b)
+{
+ const php_uri_query_param_list_entry *entry_a = Z_PTR(a->val);
+ const php_uri_query_param_list_entry *entry_b = Z_PTR(b->val);
+ const int result = zend_binary_strcmp(
+ ZSTR_VAL(entry_a->key), ZSTR_LEN(entry_a->key), ZSTR_VAL(entry_b->key), ZSTR_LEN(entry_b->key));
+
+ return result != 0 ? result : php_uri_query_params_compare_original_order(a, b);
+}
+
+static lxb_codepoint_t php_uri_query_params_next_codepoint(const lxb_char_t **p, const lxb_char_t *end)
+{
+ if (**p < 0x80) {
+ return *(*p)++;
+ }
+
+ lxb_encoding_decode_t decoder = {0};
+ const lxb_codepoint_t cp = lxb_encoding_decode_utf_8_single(&decoder, p, end);
+
+ if (cp == LXB_ENCODING_DECODE_ERROR || cp == LXB_ENCODING_DECODE_CONTINUE) {
+ return LXB_ENCODING_REPLACEMENT_CODEPOINT;
+ }
+
+ return cp;
+}
+
+static int php_uri_query_params_compare_utf16(Bucket *a, Bucket *b)
+{
+ const php_uri_query_param_list_entry *entry_a = Z_PTR(a->val);
+ const php_uri_query_param_list_entry *entry_b = Z_PTR(b->val);
+
+ const lxb_char_t *p = (const lxb_char_t *) ZSTR_VAL(entry_a->key);
+ const lxb_char_t *q = (const lxb_char_t *) ZSTR_VAL(entry_b->key);
+
+ const lxb_char_t *end_a = p + ZSTR_LEN(entry_a->key);
+ const lxb_char_t *end_b = q + ZSTR_LEN(entry_b->key);
+
+ while (p < end_a && q < end_b) {
+ const lxb_codepoint_t cp_a = php_uri_query_params_next_codepoint(&p, end_a);
+ const lxb_codepoint_t cp_b = php_uri_query_params_next_codepoint(&q, end_b);
+
+ if (cp_a == cp_b) {
+ continue;
+ }
+
+ /* UTF-16 follows code point order except that surrogate pairs precede U+E000..U+FFFF. */
+ if (cp_a >= 0xE000 && cp_b >= 0xE000 && (cp_a > 0xFFFF) != (cp_b > 0xFFFF)) {
+ return cp_a > 0xFFFF ? -1 : 1;
+ }
+
+ return (int) cp_a - (int) cp_b;
+ }
+
+ if (p < end_a || q < end_b) {
+ return p < end_a ? 1 : -1;
+ }
+
+ return php_uri_query_params_compare_original_order(a, b);
+}
+
+ZEND_ATTRIBUTE_NONNULL static void php_uri_query_params_sort_entries(
+ php_uri_query_params_object *object, const bucket_compare_func_t compare
+) {
+ if (object->tombstone_count > 0) {
+ php_uri_query_params_remove_tombstones(object);
+ }
+
+ zend_hash_sort(&object->entry_list, compare, true);
+
+ php_uri_query_params_rebuild_lookup(&object->entry_list, &object->entry_lookup_table);
+}
+
+static void php_uri_query_params_tombstone_entry(
+ php_uri_query_params_object *query_params_object, php_uri_query_param_list_entry *list_entry
+) {
+ if (list_entry->key == NULL) {
+ return;
+ }
+
+ zend_string_release(list_entry->key);
+ list_entry->key = NULL;
+ if (list_entry->value != NULL) {
+ zend_string_release(list_entry->value);
+ list_entry->value = NULL;
+ }
+
+ list_entry->next_index = UINT32_MAX;
+ query_params_object->tombstone_count++;
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) static void php_uri_query_params_delete_entries(
+ php_uri_query_params_object *query_params_object, zend_string *name
+) {
+ const php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+ if (lookup_entry == NULL) {
+ return;
+ }
+
+ uint32_t index = lookup_entry->first_index;
+ while (index != UINT32_MAX) {
+ php_uri_query_param_list_entry *list_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, index);
+ ZEND_ASSERT(list_entry != NULL);
+
+ const uint32_t next = list_entry->next_index;
+ php_uri_query_params_tombstone_entry(query_params_object, list_entry);
+ index = next;
+ }
+
+ zend_hash_del(&query_params_object->entry_lookup_table, name);
+
+ php_uri_query_params_cleanup_tombstones(query_params_object);
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) static void php_uri_query_params_delete_entries_with_value(
+ php_uri_query_params_object *query_params_object, zend_string *name, const zend_string *value
+) {
+ php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+ if (lookup_entry == NULL) {
+ return;
+ }
+
+ uint32_t index = lookup_entry->first_index;
+ uint32_t new_first = UINT32_MAX;
+ uint32_t new_last = UINT32_MAX;
+ php_uri_query_param_list_entry *prev_list_entry = NULL;
+
+ while (index != UINT32_MAX) {
+ php_uri_query_param_list_entry *list_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, index);
+ ZEND_ASSERT(list_entry != NULL);
+
+ const uint32_t next = list_entry->next_index;
+
+ const bool should_delete = (value == NULL && list_entry->value == NULL) ||
+ (value != NULL && list_entry->value != NULL && zend_string_equal_content(value, list_entry->value));
+
+ if (should_delete) {
+ php_uri_query_params_tombstone_entry(query_params_object, list_entry);
+
+ /* Rebuild the same key list */
+ if (prev_list_entry != NULL) {
+ prev_list_entry->next_index = next;
+ }
+ } else {
+ if (new_first == UINT32_MAX) {
+ new_first = index;
+ }
+ new_last = index;
+ prev_list_entry = list_entry;
+ }
+
+ index = next;
+ }
+
+ /* Either delete the lookup entry if no list entries remain, or update it with the new data. */
+ if (new_first == UINT32_MAX) {
+ zend_hash_del(&query_params_object->entry_lookup_table, name);
+ } else {
+ php_uri_query_param_list_entry *last_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, new_last);
+ ZEND_ASSERT(last_entry != NULL);
+ last_entry->next_index = UINT32_MAX;
+
+ lookup_entry->first_index = new_first;
+ lookup_entry->last_index = new_last;
+ }
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2) static zend_result php_uri_query_params_set_entry(
+ php_uri_query_params_object *query_params_object, zend_string *name, zend_string *value
+) {
+ php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&query_params_object->entry_lookup_table, name);
+ if (lookup_entry == NULL) {
+ return php_uri_query_params_append_entry(query_params_object, name, value);
+ }
+
+ /* Overwrite first occurrence */
+ php_uri_query_param_list_entry *first_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, lookup_entry->first_index);
+ ZEND_ASSERT(first_entry != NULL);
+
+ if (first_entry->value != NULL) {
+ zend_string_release(first_entry->value);
+ }
+ first_entry->value = value != NULL ? zend_string_copy(value) : NULL;
+
+ /* Tombstone the rest of the occurrences */
+ uint32_t index = first_entry->next_index;
+ first_entry->next_index = UINT32_MAX;
+
+ while (index != UINT32_MAX) {
+ php_uri_query_param_list_entry *list_entry = zend_hash_index_find_ptr(&query_params_object->entry_list, index);
+ ZEND_ASSERT(list_entry != NULL);
+
+ const uint32_t next = list_entry->next_index;
+ php_uri_query_params_tombstone_entry(query_params_object, list_entry);
+ index = next;
+ }
+
+ /* Update the lookup entry */
+ lookup_entry->last_index = lookup_entry->first_index;
+
+ php_uri_query_params_cleanup_tombstones(query_params_object);
+
+ return SUCCESS;
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_object *php_uri_object_query_params_create_object(zend_class_entry *ce)
+{
+ php_uri_query_params_object *uri_query_params_object = zend_object_alloc(sizeof(*uri_query_params_object), ce);
+
+ zend_object_std_init(&uri_query_params_object->std, ce);
+ object_properties_init(&uri_query_params_object->std, ce);
+
+ uri_query_params_object->is_initialized = false;
+ uri_query_params_object->tombstone_count = 0;
+
+ return &uri_query_params_object->std;
+}
+
+ZEND_ATTRIBUTE_NONNULL void php_uri_query_params_object_free(php_uri_query_params_object *uri_query_params_object)
+{
+ if (uri_query_params_object->is_initialized) {
+ zend_hash_destroy(&uri_query_params_object->entry_list);
+ zend_hash_destroy(&uri_query_params_object->entry_lookup_table);
+ uri_query_params_object->tombstone_count = 0;
+ }
+}
+
+ZEND_ATTRIBUTE_NONNULL void php_uri_query_params_object_handler_free(zend_object *object)
+{
+ php_uri_query_params_object *uri_query_params_object = php_uri_query_params_object_from_obj(object);
+
+ php_uri_query_params_object_free(uri_query_params_object);
+
+ zend_object_std_dtor(&uri_query_params_object->std);
+}
+
+static void php_uri_query_param_list_entry_copy(zval *zv)
+{
+ const php_uri_query_param_list_entry *original = Z_PTR_P(zv);
+ php_uri_query_param_list_entry *copy = emalloc(sizeof(*copy));
+
+ copy->key = original->key != NULL ? zend_string_copy(original->key) : NULL;
+ copy->value = original->value != NULL ? zend_string_copy(original->value) : NULL;
+ copy->next_index = original->next_index;
+
+ Z_PTR_P(zv) = copy;
+}
+
+static void php_uri_query_param_lookup_entry_copy(zval *zv)
+{
+ const php_uri_query_param_lookup_entry *original = Z_PTR_P(zv);
+ php_uri_query_param_lookup_entry *copy = emalloc(sizeof(*copy));
+
+ copy->first_index = original->first_index;
+ copy->last_index = original->last_index;
+
+ Z_PTR_P(zv) = copy;
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_object *php_uri_query_params_object_handler_clone(zend_object *object)
+{
+ const php_uri_query_params_object *uri_query_params_object = php_uri_query_params_object_from_obj(object);
+
+ php_uri_query_params_object *new_uri_query_params_object = php_uri_query_params_object_from_obj(
+ object->ce->create_object(object->ce)
+ );
+
+ if (uri_query_params_object->is_initialized) {
+ zend_hash_init(&new_uri_query_params_object->entry_list, zend_hash_num_elements(&uri_query_params_object->entry_list),
+ NULL, uri_query_params_object->entry_list.pDestructor, 0);
+ zend_hash_init(&new_uri_query_params_object->entry_lookup_table, zend_hash_num_elements(&uri_query_params_object->entry_lookup_table),
+ NULL, uri_query_params_object->entry_lookup_table.pDestructor, 0);
+ zend_hash_copy(&new_uri_query_params_object->entry_list, &uri_query_params_object->entry_list, php_uri_query_param_list_entry_copy);
+ zend_hash_copy(&new_uri_query_params_object->entry_lookup_table, &uri_query_params_object->entry_lookup_table, php_uri_query_param_lookup_entry_copy);
+ new_uri_query_params_object->tombstone_count = uri_query_params_object->tombstone_count;
+ new_uri_query_params_object->is_initialized = true;
+ }
+ zend_objects_clone_members(&new_uri_query_params_object->std, &uri_query_params_object->std);
+
+ return &new_uri_query_params_object->std;
+}
+
+ZEND_ATTRIBUTE_NONNULL static bool php_uri_query_params_object_can_be_reused(const zend_object *object)
+{
+ /* Only reuse an object when neither a strong nor a weak reference can observe the change. */
+ return GC_REFCOUNT(object) == 1 && !(GC_FLAGS(object) & IS_OBJ_WEAKLY_REFERENCED);
+}
+
+ZEND_ATTRIBUTE_NONNULL static php_uri_query_params_object *php_uri_query_params_object_clone_for_modification(
+ zend_object *object, zval *return_value
+) {
+ if (php_uri_query_params_object_can_be_reused(object)) {
+ ZVAL_OBJ_COPY(return_value, object);
+ } else {
+ zend_object *new_object = object->handlers->clone_obj(object);
+ if (new_object == NULL) {
+ return NULL;
+ }
+ ZVAL_OBJ(return_value, new_object);
+ }
+
+ return Z_URI_QUERY_PARAMS_OBJECT_P(return_value);
+}
+
+typedef struct php_uri_query_params_iterator {
+ zend_object_iterator intern;
+ php_uri_query_params_object *query_params_object;
+ uint32_t current_index;
+ zval current_value;
+} php_uri_query_params_iterator;
+
+static void php_uri_query_params_iterator_dtor(zend_object_iterator *iter)
+{
+ php_uri_query_params_iterator *iterator = (php_uri_query_params_iterator *) iter;
+ zval_ptr_dtor(&iterator->current_value);
+ zval_ptr_dtor(&iterator->intern.data);
+}
+
+static php_uri_query_param_list_entry *php_uri_query_params_iterator_current_entry(
+ php_uri_query_params_iterator *iterator
+) {
+ const php_uri_query_params_object *obj = iterator->query_params_object;
+
+ if (!obj->is_initialized) {
+ return NULL;
+ }
+
+ while (iterator->current_index < zend_hash_num_elements(&obj->entry_list)) {
+ php_uri_query_param_list_entry *entry = zend_hash_index_find_ptr(&obj->entry_list, iterator->current_index);
+
+ if (entry != NULL && entry->key != NULL) {
+ return entry;
+ }
+
+ iterator->current_index++;
+ }
+
+ return NULL;
+}
+
+static zend_result php_uri_query_params_iterator_valid(zend_object_iterator *iter)
+{
+ php_uri_query_params_iterator *iterator = (php_uri_query_params_iterator *) iter;
+
+ return php_uri_query_params_iterator_current_entry(iterator) != NULL ? SUCCESS : FAILURE;
+}
+
+static zval *php_uri_query_params_iterator_current_data(zend_object_iterator *iter)
+{
+ php_uri_query_params_iterator *iterator = (php_uri_query_params_iterator *) iter;
+ const php_uri_query_param_list_entry *entry = php_uri_query_params_iterator_current_entry(iterator);
+
+ if (entry == NULL) {
+ return NULL;
+ }
+
+ zval_ptr_dtor(&iterator->current_value);
+ array_init_size(&iterator->current_value, 2);
+
+ zval key_zv, value_zv;
+ ZVAL_STR_COPY(&key_zv, entry->key);
+ if (entry->value != NULL) {
+ ZVAL_STR_COPY(&value_zv, entry->value);
+ } else {
+ ZVAL_NULL(&value_zv);
+ }
+
+ zend_hash_next_index_insert(Z_ARRVAL(iterator->current_value), &key_zv);
+ zend_hash_next_index_insert(Z_ARRVAL(iterator->current_value), &value_zv);
+
+ return &iterator->current_value;
+}
+
+static void php_uri_query_params_iterator_move_forward(zend_object_iterator *iter)
+{
+ php_uri_query_params_iterator *iterator = (php_uri_query_params_iterator *) iter;
+ if (php_uri_query_params_iterator_current_entry(iterator) != NULL) {
+ iterator->current_index++;
+ }
+}
+
+static void php_uri_query_params_iterator_rewind(zend_object_iterator *iter)
+{
+ php_uri_query_params_iterator *iterator = (php_uri_query_params_iterator *) iter;
+ iterator->current_index = 0;
+}
+
+static const zend_object_iterator_funcs php_uri_query_params_iterator_funcs = {
+ .dtor = php_uri_query_params_iterator_dtor,
+ .valid = php_uri_query_params_iterator_valid,
+ .get_current_data = php_uri_query_params_iterator_current_data,
+ .get_current_key = NULL,
+ .move_forward = php_uri_query_params_iterator_move_forward,
+ .rewind = php_uri_query_params_iterator_rewind,
+ .invalidate_current = NULL,
+ .get_gc = NULL,
+};
+
+ZEND_ATTRIBUTE_NONNULL zend_object_iterator *php_uri_object_query_params_get_iterator(
+ zend_class_entry *ce, zval *object, const int by_ref)
+{
+ if (by_ref) {
+ zend_throw_error(NULL, "An iterator cannot be used with foreach by reference");
+ return NULL;
+ }
+
+ php_uri_query_params_iterator *iterator = emalloc(sizeof(php_uri_query_params_iterator));
+
+ zend_iterator_init(&iterator->intern);
+ iterator->intern.funcs = &php_uri_query_params_iterator_funcs;
+
+ ZVAL_OBJ_COPY(&iterator->intern.data, Z_OBJ_P(object));
+ iterator->query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(object);
+ iterator->current_index = 0;
+ ZVAL_UNDEF(&iterator->current_value);
+
+ return &iterator->intern;
+}
+
+static void php_uri_query_param_list_entry_dtor(zval *zv)
+{
+ php_uri_query_param_list_entry *list_entry = Z_PTR_P(zv);
+
+ if (list_entry->key != NULL) {
+ zend_string_release(list_entry->key);
+ }
+
+ if (list_entry->value != NULL) {
+ zend_string_release(list_entry->value);
+ }
+
+ efree(list_entry);
+}
+
+static void php_uri_query_param_lookup_entry_dtor(zval *zv)
+{
+ efree(Z_PTR_P(zv));
+}
+
+ZEND_ATTRIBUTE_NONNULL static void php_uri_query_params_object_init(php_uri_query_params_object *object)
+{
+ ZEND_ASSERT(!object->is_initialized);
+ zend_hash_init(&object->entry_list, 8, NULL, php_uri_query_param_list_entry_dtor, 0);
+ zend_hash_init(&object->entry_lookup_table, 8, NULL, php_uri_query_param_lookup_entry_dtor, 0);
+ object->is_initialized = true;
+}
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1, 3) zend_result php_uri_query_params_parse(
+ const char *query_str_first, const size_t query_str_length, php_uri_query_params_object *query_params_object,
+ const php_uri_query_params_parsing_method parsing_method, const bool silent, const zend_long max_param_count
+) {
+ php_uri_query_params_object_init(query_params_object);
+
+ /* Validate the encoded query component, not the decoded parameter bytes. */
+ if (parsing_method == PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC3986
+ && !php_uri_parser_rfc3986_query_is_well_formed(query_str_first, query_str_length)
+ ) {
+ if (!silent) {
+ zend_throw_exception(php_uri_ce_invalid_query_params_exception, "The specified query string is malformed", 0);
+ }
+ return FAILURE;
+ }
+
+ const char *p = query_str_first;
+ const char *end = query_str_first + query_str_length;
+
+ /* The URLSearchParams constructor removes exactly one leading question mark. */
+ if (parsing_method == PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL_SEARCH_PARAMS && p < end && *p == '?') {
+ p++;
+ }
+
+ if (p == end) {
+ return SUCCESS;
+ }
+
+ const char *ampersand;
+ do {
+ const char *pair_start = p;
+ ampersand = memchr(p, '&', (size_t)(end - p));
+ const char *pair_end = ampersand != NULL ? ampersand : end;
+ const size_t pair_len = (size_t)(pair_end - pair_start);
+ p = ampersand != NULL ? ampersand + 1 : end;
+
+ if (pair_len == 0
+ && (parsing_method == PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL
+ || parsing_method == PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL_SEARCH_PARAMS)
+ ) {
+ continue;
+ }
+
+ if (UNEXPECTED(max_param_count > 0 && zend_hash_num_elements(&query_params_object->entry_list) >= max_param_count)) {
+ if (!silent) {
+ zend_throw_exception(php_uri_ce_invalid_query_params_exception, "The specified query string contains too many parameters", 0);
+ }
+ return FAILURE;
+ }
+
+ const char *eq = memchr(pair_start, '=', pair_len);
+
+ const char *name_start;
+ size_t name_len;
+ const char *value_start;
+ size_t value_len;
+
+ if (eq == NULL) {
+ name_start = pair_start;
+ name_len = pair_len;
+ value_start = NULL;
+ value_len = 0;
+ } else {
+ name_start = pair_start;
+ name_len = (size_t)(eq - pair_start);
+ value_start = eq + 1;
+ value_len = (size_t) (pair_end - value_start);
+ }
+
+ zend_string *name;
+ zend_string *value;
+
+ switch (parsing_method) {
+ case PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC1866:
+ name = php_uri_parser_rfc3986_query_component_percent_decode(name_start, name_len, true);
+ value = php_uri_parser_rfc3986_query_component_percent_decode(value_start, value_len, true);
+ break;
+ case PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC3986:
+ name = php_uri_parser_rfc3986_query_component_percent_decode(name_start, name_len, false);
+ value = php_uri_parser_rfc3986_query_component_percent_decode(value_start, value_len, false);
+ break;
+ case PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL:
+ case PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL_SEARCH_PARAMS:
+ name = php_uri_parser_whatwg_query_component_percent_decode(name_start, name_len);
+ if (UNEXPECTED(name == NULL)) {
+ ZEND_ASSERT(ZEND_HAS_OOM());
+ zend_handle_delayed_oom();
+ return FAILURE;
+ }
+ if (value_start == NULL) {
+ value = ZSTR_EMPTY_ALLOC();
+ } else {
+ value = php_uri_parser_whatwg_query_component_percent_decode(value_start, value_len);
+ if (UNEXPECTED(value == NULL)) {
+ zend_string_release(name);
+ ZEND_ASSERT(ZEND_HAS_OOM());
+ zend_handle_delayed_oom();
+ return FAILURE;
+ }
+ }
+ break;
+ default: ZEND_UNREACHABLE();
+ }
+
+ const zend_result result = php_uri_query_params_append_entry(query_params_object, name, value);
+
+ zend_string_release(name);
+ if (value != NULL) {
+ zend_string_release(value);
+ }
+
+ if (UNEXPECTED(result == FAILURE)) {
+ if (!silent) {
+ zend_throw_exception(php_uri_ce_invalid_query_params_exception, "Failed to parse the specified query string", 0);
+ }
+
+ return FAILURE;
+ }
+ } while (ampersand != NULL);
+
+ return SUCCESS;
+}
+
+ZEND_ATTRIBUTE_NONNULL static void throw_cannot_recompose_uri_to_string(const zend_object *object)
+{
+ zend_throw_exception_ex(php_uri_ce_error, 0, "Cannot recompose %pS to a string", object->ce->name);
+}
+
+ZEND_ATTRIBUTE_NONNULL static zend_string *php_uri_query_params_to_rfc1866_string(const php_uri_query_params_object *uri_query_params_object)
+{
+ return php_uri_parser_rfc3986_query_params_to_string(uri_query_params_object, true);
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_query_params_to_rfc3986_string(const php_uri_query_params_object *uri_query_params_object)
+{
+ return php_uri_parser_rfc3986_query_params_to_string(uri_query_params_object, false);
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_query_params_to_whatwg_string(const php_uri_query_params_object *uri_query_params_object)
+{
+ return php_uri_parser_whatwg_query_params_to_string(uri_query_params_object);
+}
+
+ZEND_ATTRIBUTE_NONNULL static HashTable *php_uri_query_params_get_debug_properties(php_uri_query_params_object *object)
+{
+ HashTable *result = zend_new_array(1);
+
+ zval params;
+ php_uri_query_params_list_entries(object, ¶ms);
+
+ zend_hash_str_add(result, ZEND_STRL("params"), ¶ms);
+
+ return result;
+}
+
+static void uri_query_params_parse(INTERNAL_FUNCTION_PARAMETERS, const php_uri_query_params_parsing_method parsing_method)
+{
+ zend_string *query_str;
+ zend_long max_param_count = PHP_URI_QUERY_PARAMS_DEFAULT_MAX_PARAM_COUNT;
+
+ ZEND_PARSE_PARAMETERS_START(1, 2)
+ Z_PARAM_STR(query_str)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(max_param_count)
+ ZEND_PARSE_PARAMETERS_END();
+
+ if (max_param_count < 0) {
+ zend_argument_value_error(2, "must be greater than or equal to 0");
+ RETURN_THROWS();
+ }
+
+ object_init_ex(return_value, zend_get_called_scope(execute_data));
+ php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(return_value);
+
+ if (php_uri_query_params_parse(ZSTR_VAL(query_str), ZSTR_LEN(query_str), uri_query_params_object,
+ parsing_method, false, max_param_count
+ ) == FAILURE) {
+ RETURN_THROWS();
+ }
+}
+
+PHP_METHOD(Uri_QueryParams, parseRfc1866)
+{
+ uri_query_params_parse(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC1866);
+}
+
+PHP_METHOD(Uri_QueryParams, parseRfc3986)
+{
+ uri_query_params_parse(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC3986);
+}
+
+PHP_METHOD(Uri_QueryParams, parseWhatWgUrlSearchParams)
+{
+ uri_query_params_parse(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL_SEARCH_PARAMS);
+}
+
+PHP_METHOD(Uri_QueryParams, fromArray)
+{
+ HashTable *query_params_arr;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ARRAY_HT(query_params_arr)
+ ZEND_PARSE_PARAMETERS_END();
+
+ object_init_ex(return_value, zend_get_called_scope(execute_data));
+ php_uri_query_params_object *object = Z_URI_QUERY_PARAMS_OBJECT_P(return_value);
+
+ php_uri_query_params_object_init(object);
+
+ if (php_uri_query_params_append_array(object, query_params_arr, NULL) == FAILURE) {
+ RETURN_THROWS();
+ }
+}
+
+PHP_METHOD(Uri_QueryParams, fromList)
+{
+ HashTable *list;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ARRAY_HT(list)
+ ZEND_PARSE_PARAMETERS_END();
+
+ if (!zend_array_is_list(list)) {
+ zend_argument_value_error(1, "must be a list of [name, value] pairs");
+ RETURN_THROWS();
+ }
+
+ object_init_ex(return_value, zend_get_called_scope(execute_data));
+ php_uri_query_params_object *object = Z_URI_QUERY_PARAMS_OBJECT_P(return_value);
+ php_uri_query_params_object_init(object);
+
+ ZEND_HASH_FOREACH_NUM_KEY_VAL(list, const zend_ulong index, const zval *pair) {
+ ZVAL_DEREF(pair);
+
+ if (Z_TYPE_P(pair) != IS_ARRAY) {
+ zend_argument_type_error(1, "must contain an array at index " ZEND_ULONG_FMT ", %s given",
+ index, zend_zval_value_name(pair));
+ RETURN_THROWS();
+ }
+
+ const HashTable *fields = Z_ARRVAL_P(pair);
+ if (zend_hash_num_elements(fields) != 2 || !zend_array_is_list(fields)) {
+ zend_argument_value_error(1, "must contain a [name, value] pair at index " ZEND_ULONG_FMT, index);
+ RETURN_THROWS();
+ }
+
+ const zval *name = zend_hash_index_find(fields, 0);
+ ZVAL_DEREF(name);
+ if (Z_TYPE_P(name) != IS_STRING) {
+ zend_argument_type_error(1, "must contain a string parameter name at index " ZEND_ULONG_FMT ", %s given",
+ index, zend_zval_value_name(name));
+ RETURN_THROWS();
+ }
+
+ zend_string *name_str = zend_string_copy(Z_STR_P(name));
+ const zend_result result = php_uri_query_params_append_array_value(object, name_str, zend_hash_index_find(fields, 1));
+ zend_string_release(name_str);
+ if (UNEXPECTED(result == FAILURE)) {
+ RETURN_THROWS();
+ }
+ } ZEND_HASH_FOREACH_END();
+}
+
+PHP_METHOD(Uri_QueryParams, __construct)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+ if (uri_query_params_object->is_initialized) {
+ zend_throw_error(NULL, "Cannot modify readonly object of class %pS", uri_query_params_object->std.ce->name);
+ RETURN_THROWS();
+ }
+
+ php_uri_query_params_object_init(uri_query_params_object);
+}
+
+PHP_METHOD(Uri_QueryParams, has)
+{
+ zend_string *name;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_STR(name)
+ ZEND_PARSE_PARAMETERS_END();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ RETVAL_BOOL(php_uri_query_params_has_entry(uri_query_params_object, name));
+}
+
+PHP_METHOD(Uri_QueryParams, hasValue)
+{
+ zend_string *name;
+ zval *value;
+
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_STR(name)
+ Z_PARAM_ZVAL(value)
+ ZEND_PARSE_PARAMETERS_END();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ zend_string *value_str = php_uri_query_params_convert_value_to_str(value, NULL);
+ if (EG(exception)) {
+ RETURN_THROWS();
+ }
+
+ RETVAL_BOOL(php_uri_query_params_has_entry_with_value(uri_query_params_object, name, value_str));
+
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+}
+
+PHP_METHOD(Uri_QueryParams, getFirst)
+{
+ zend_string *name;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_STR(name)
+ ZEND_PARSE_PARAMETERS_END();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ php_uri_query_params_find_first_value(uri_query_params_object, name, return_value);
+}
+
+PHP_METHOD(Uri_QueryParams, getLast)
+{
+ zend_string *name;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_STR(name)
+ ZEND_PARSE_PARAMETERS_END();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ php_uri_query_params_find_last_value(uri_query_params_object, name, return_value);
+}
+
+PHP_METHOD(Uri_QueryParams, getAll)
+{
+ zend_string *name;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_STR(name)
+ ZEND_PARSE_PARAMETERS_END();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ php_uri_query_params_find_all_values(uri_query_params_object, name, return_value);
+}
+
+PHP_METHOD(Uri_QueryParams, toList)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ php_uri_query_params_list_entries(uri_query_params_object, return_value);
+}
+
+PHP_METHOD(Uri_QueryParams, getIterator)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ zend_create_internal_iterator_zval(return_value, ZEND_THIS);
+}
+
+PHP_METHOD(Uri_QueryParams, count)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ RETVAL_LONG(zend_array_count(&uri_query_params_object->entry_list) - uri_query_params_object->tombstone_count);
+}
+
+PHP_METHOD(Uri_QueryParams, append)
+{
+ zend_string *name;
+ zval *value;
+
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_STR(name)
+ Z_PARAM_ZVAL(value)
+ ZEND_PARSE_PARAMETERS_END();
+
+ zend_string *value_str = php_uri_query_params_convert_value_to_str(value, NULL);
+ if (EG(exception)) {
+ RETURN_THROWS();
+ }
+
+ php_uri_query_params_object *new_object = php_uri_query_params_object_clone_for_modification(Z_OBJ_P(ZEND_THIS), return_value);
+ if (new_object == NULL) {
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+ RETURN_THROWS();
+ }
+
+ const zend_result result = php_uri_query_params_append_entry(new_object, name, value_str);
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+ if (UNEXPECTED(result == FAILURE)) {
+ /* This should be unreachable in practice. */
+ zend_throw_exception(php_uri_ce_error, "Failed to append the query parameter", 0);
+ RETURN_THROWS();
+ }
+}
+
+PHP_METHOD(Uri_QueryParams, set)
+{
+ zend_string *name;
+ zval *value;
+
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_STR(name)
+ Z_PARAM_ZVAL(value)
+ ZEND_PARSE_PARAMETERS_END();
+
+ zend_string *value_str = php_uri_query_params_convert_value_to_str(value, NULL);
+ if (EG(exception)) {
+ RETURN_THROWS();
+ }
+
+ php_uri_query_params_object *new_object = php_uri_query_params_object_clone_for_modification(Z_OBJ_P(ZEND_THIS), return_value);
+ if (new_object == NULL) {
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+ RETURN_THROWS();
+ }
+
+ const zend_result result = php_uri_query_params_set_entry(new_object, name, value_str);
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+ if (UNEXPECTED(result == FAILURE)) {
+ /* This should be unreachable in practice. */
+ zend_throw_exception(php_uri_ce_error, "Failed to set the query parameter", 0);
+ RETURN_THROWS();
+ }
+}
+
+PHP_METHOD(Uri_QueryParams, delete)
+{
+ zend_string *name;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_STR(name)
+ ZEND_PARSE_PARAMETERS_END();
+
+ php_uri_query_params_object *new_object = php_uri_query_params_object_clone_for_modification(Z_OBJ_P(ZEND_THIS), return_value);
+ if (new_object == NULL) {
+ RETURN_THROWS();
+ }
+
+ php_uri_query_params_delete_entries(new_object, name);
+}
+
+PHP_METHOD(Uri_QueryParams, deleteValue)
+{
+ zend_string *name;
+ zval *value;
+
+ ZEND_PARSE_PARAMETERS_START(2, 2)
+ Z_PARAM_STR(name)
+ Z_PARAM_ZVAL(value)
+ ZEND_PARSE_PARAMETERS_END();
+
+ zend_string *value_str = php_uri_query_params_convert_value_to_str(value, NULL);
+ if (EG(exception)) {
+ RETURN_THROWS();
+ }
+
+ php_uri_query_params_object *new_object = php_uri_query_params_object_clone_for_modification(Z_OBJ_P(ZEND_THIS), return_value);
+ if (new_object == NULL) {
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+ RETURN_THROWS();
+ }
+
+ php_uri_query_params_delete_entries_with_value(new_object, name, value_str);
+ if (value_str != NULL) {
+ zend_string_release(value_str);
+ }
+}
+
+static void php_uri_query_params_sort(INTERNAL_FUNCTION_PARAMETERS, const bucket_compare_func_t compare)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ php_uri_query_params_object *new_object = php_uri_query_params_object_clone_for_modification(Z_OBJ_P(ZEND_THIS), return_value);
+ if (new_object == NULL) {
+ RETURN_THROWS();
+ }
+
+ php_uri_query_params_sort_entries(new_object, compare);
+}
+
+PHP_METHOD(Uri_QueryParams, sortByBytes)
+{
+ php_uri_query_params_sort(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_query_params_compare_bytes);
+}
+
+PHP_METHOD(Uri_QueryParams, sortByUtf16)
+{
+ php_uri_query_params_sort(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_uri_query_params_compare_utf16);
+}
+
+/* Return zero for literal names, including names with malformed bracket notation. */
+ZEND_ATTRIBUTE_NONNULL static size_t php_uri_query_params_array_key_depth(
+ const zend_string *name, size_t *root_len
+) {
+ const char *key = ZSTR_VAL(name);
+ const char *opening_bracket = memchr(key, '[', ZSTR_LEN(name));
+ *root_len = ZSTR_LEN(name);
+
+ /* Either no opening bracket was found, or a closing bracket precedes it */
+ if (opening_bracket == NULL || memchr(key, ']', opening_bracket - key) != NULL) {
+ return 0;
+ }
+
+ size_t depth = 0;
+ const char *p = opening_bracket;
+
+ const char *end = key + ZSTR_LEN(name);
+ while (p < end) {
+ if (*p++ != '[') {
+ return 0;
+ }
+
+ while (p < end && *p != ']') {
+ /* Check if there is an opening bracket before the previous one was closed */
+ if (*p++ == '[') {
+ return 0;
+ }
+ }
+
+ /* Check whether we reached the end of the input before finding the closing bracket */
+ if (p == end) {
+ return 0;
+ }
+
+ p++;
+ depth++;
+ }
+
+ *root_len = opening_bracket - key;
+
+ return depth;
+}
+
+ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_query_params_add_entry_to_array(
+ HashTable *result, const php_uri_query_params_object *object,
+ const php_uri_query_param_list_entry *entry, zend_long max_nesting_level
+) {
+ size_t root_len;
+ size_t depth = php_uri_query_params_array_key_depth(entry->key, &root_len);
+ const char *key = ZSTR_VAL(entry->key);
+ const char *end = key + ZSTR_LEN(entry->key);
+
+ if (depth == 0) {
+ const php_uri_query_param_lookup_entry *lookup_entry = zend_hash_find_ptr(&object->entry_lookup_table, entry->key);
+ bool is_list = lookup_entry->first_index != lookup_entry->last_index;
+ if (is_list && max_nesting_level == 0) {
+ goto nesting_error;
+ }
+
+ zval value;
+ if (entry->value == NULL) {
+ ZVAL_NULL(&value);
+ } else {
+ ZVAL_STR_COPY(&value, entry->value);
+ }
+
+ if (is_list) {
+ zval *list = zend_symtable_str_find(result, key, root_len);
+ if (list == NULL) {
+ zval new_list;
+ array_init(&new_list);
+ list = zend_symtable_str_update(result, key, root_len, &new_list);
+ }
+ zend_hash_next_index_insert(Z_ARRVAL_P(list), &value);
+ } else {
+ zend_symtable_str_update(result, key, root_len, &value);
+ }
+
+ return SUCCESS;
+ }
+
+ if (depth > (zend_ulong) max_nesting_level) {
+ goto nesting_error;
+ }
+
+ /* Reject bracket notation if the root also appears as a plain parameter name, e.g. "foo=1&foo[bar]=2". */
+ if (zend_hash_str_exists(&object->entry_lookup_table, key, root_len)) {
+ goto conflict_error;
+ }
+
+ HashTable *current = result;
+ const char *segment = key;
+ size_t segment_len = root_len;
+ const char *next = key + root_len;
+ bool append = false;
+
+ while (true) {
+ bool is_leaf = next == end;
+ zval *existing = append ? NULL : zend_symtable_str_find(current, segment, segment_len);
+ if (existing == NULL) {
+ zval value;
+
+ if (!is_leaf) {
+ array_init(&value);
+ } else if (entry->value == NULL) {
+ ZVAL_NULL(&value);
+ } else {
+ ZVAL_STR_COPY(&value, entry->value);
+ }
+
+ if (append) {
+ existing = zend_hash_next_index_insert(current, &value);
+ } else {
+ existing = zend_symtable_str_update(current, segment, segment_len, &value);
+ }
+
+ if (UNEXPECTED(existing == NULL)) {
+ zval_ptr_dtor(&value);
+ zend_throw_exception_ex(php_uri_ce_invalid_query_params_exception, 0,
+ "Cannot append an array element for query parameter \"%pS\"", entry->key);
+ return FAILURE;
+ }
+ } else {
+ if (is_leaf || Z_TYPE_P(existing) != IS_ARRAY) {
+ goto conflict_error;
+ }
+ }
+
+ if (is_leaf) {
+ return SUCCESS;
+ }
+
+ current = Z_ARRVAL_P(existing);
+ segment = next + 1;
+ const char *close = memchr(segment, ']', end - segment);
+ ZEND_ASSERT(close != NULL);
+ segment_len = close - segment;
+ append = segment_len == 0;
+ next = close + 1;
+ }
+
+nesting_error:
+ zend_throw_exception_ex(php_uri_ce_invalid_query_params_exception, 0,
+ "The query parameter \"%pS\" exceeds the maximum nesting level of " ZEND_LONG_FMT,
+ entry->key, max_nesting_level);
+ return FAILURE;
+
+conflict_error:
+ zend_throw_exception_ex(php_uri_ce_invalid_query_params_exception, 0,
+ "The query parameter \"%pS\" has conflicting array paths", entry->key);
+ return FAILURE;
+}
+
+PHP_METHOD(Uri_QueryParams, withArray)
+{
+ HashTable *query_params_arr;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ARRAY_HT(query_params_arr)
+ ZEND_PARSE_PARAMETERS_END();
+
+ php_uri_query_params_object *object;
+
+ if (php_uri_query_params_object_can_be_reused(Z_OBJ_P(ZEND_THIS))) {
+ ZVAL_OBJ_COPY(return_value, Z_OBJ_P(ZEND_THIS));
+ object = Z_URI_QUERY_PARAMS_OBJECT_P(return_value);
+ zend_hash_clean(&object->entry_list);
+ zend_hash_clean(&object->entry_lookup_table);
+ object->tombstone_count = 0;
+ } else {
+ object_init_ex(return_value, Z_OBJCE_P(ZEND_THIS));
+ object = Z_URI_QUERY_PARAMS_OBJECT_P(return_value);
+ php_uri_query_params_object_init(object);
+ }
+
+ if (php_uri_query_params_append_array(object, query_params_arr, NULL) == FAILURE) {
+ RETURN_THROWS();
+ }
+}
+
+PHP_METHOD(Uri_QueryParams, toArray)
+{
+ zend_long max_nesting_level = 64;
+
+ ZEND_PARSE_PARAMETERS_START(0, 1)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_LONG(max_nesting_level)
+ ZEND_PARSE_PARAMETERS_END();
+
+ if (max_nesting_level < 0) {
+ zend_argument_value_error(1, "must be greater than or equal to 0");
+ RETURN_THROWS();
+ }
+
+ const php_uri_query_params_object *object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ zend_array *result = zend_new_array(0);
+ ZEND_HASH_FOREACH_PTR(&object->entry_list, php_uri_query_param_list_entry *entry) {
+ if (entry->key == NULL) {
+ continue;
+ }
+
+ if (php_uri_query_params_add_entry_to_array(result, object, entry, max_nesting_level) == FAILURE) {
+ zend_array_destroy(result);
+ RETURN_THROWS();
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ RETURN_ARR(result);
+}
+
+PHP_METHOD(Uri_QueryParams, toRfc1866String)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ zend_string *result = php_uri_query_params_to_rfc1866_string(uri_query_params_object);
+ if (result == NULL) {
+ throw_cannot_recompose_uri_to_string(Z_OBJ_P(ZEND_THIS));
+ RETURN_THROWS();
+ }
+
+ ZVAL_STR(return_value, result);
+}
+
+PHP_METHOD(Uri_QueryParams, toRfc3986String)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ zend_string *result = php_uri_query_params_to_rfc3986_string(uri_query_params_object);
+ if (result == NULL) {
+ throw_cannot_recompose_uri_to_string(Z_OBJ_P(ZEND_THIS));
+ RETURN_THROWS();
+ }
+
+ ZVAL_STR(return_value, result);
+}
+
+PHP_METHOD(Uri_QueryParams, toWhatWgUrlString)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ const php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ zend_string *result = php_uri_query_params_to_whatwg_string(uri_query_params_object);
+ if (result == NULL) {
+ throw_cannot_recompose_uri_to_string(Z_OBJ_P(ZEND_THIS));
+ RETURN_THROWS();
+ }
+
+ ZVAL_STR(return_value, result);
+}
+
+PHP_METHOD(Uri_QueryParams, __serialize)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ /* Serialize the parameter list without recomposing or converting its values. */
+ zval params;
+ php_uri_query_params_list_entries(uri_query_params_object, ¶ms);
+
+ array_init(return_value);
+
+ zval arr;
+ array_init(&arr);
+ zend_hash_str_add_new(Z_ARRVAL(arr), ZEND_STRL(PHP_URI_SERIALIZE_QUERY_PARAMS_FIELD_NAME), ¶ms);
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
+
+ /* Serialize regular properties: second array */
+ ZVAL_EMPTY_ARRAY(&arr);
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
+}
+
+static void uri_query_params_unserialize(INTERNAL_FUNCTION_PARAMETERS)
+{
+ HashTable *data;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ARRAY_HT(data)
+ ZEND_PARSE_PARAMETERS_END();
+
+ php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+ if (uri_query_params_object->is_initialized) {
+ /* Intentionally throw two exceptions for proper chaining. */
+ zend_throw_error(NULL, "Cannot modify readonly object of class %pS", uri_query_params_object->std.ce->name);
+ zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_query_params_object->std.ce->name);
+ RETURN_THROWS();
+ }
+
+ /* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
+ if (zend_hash_num_elements(data) != 2) {
+ goto invalid_data;
+ }
+
+ /* Validate the complete state before initializing the readonly object. */
+ const zval *arr = zend_hash_index_find(data, 0);
+ if (arr == NULL || Z_TYPE_P(arr) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_P(arr)) != 1) {
+ goto invalid_data;
+ }
+
+ const zval *params = zend_hash_str_find(Z_ARRVAL_P(arr), ZEND_STRL(PHP_URI_SERIALIZE_QUERY_PARAMS_FIELD_NAME));
+ if (params == NULL || Z_TYPE_P(params) != IS_ARRAY || !zend_array_is_list(Z_ARRVAL_P(params))) {
+ goto invalid_data;
+ }
+
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(params), zval *param) {
+ if (Z_TYPE_P(param) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_P(param)) != 2) {
+ goto invalid_data;
+ }
+ const zval *name = zend_hash_index_find(Z_ARRVAL_P(param), 0);
+ const zval *value = zend_hash_index_find(Z_ARRVAL_P(param), 1);
+ if (name == NULL || Z_TYPE_P(name) != IS_STRING
+ || value == NULL || (Z_TYPE_P(value) != IS_STRING && Z_TYPE_P(value) != IS_NULL)) {
+ goto invalid_data;
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ arr = zend_hash_index_find(data, 1);
+ if (arr == NULL || Z_TYPE_P(arr) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_P(arr)) != 0) {
+ goto invalid_data;
+ }
+
+ php_uri_query_params_object_init(uri_query_params_object);
+
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(params), zval *param) {
+ const zval *name = zend_hash_index_find(Z_ARRVAL_P(param), 0);
+ const zval *value = zend_hash_index_find(Z_ARRVAL_P(param), 1);
+ if (php_uri_query_params_append_entry(uri_query_params_object, Z_STR_P(name),
+ Z_TYPE_P(value) == IS_NULL ? NULL : Z_STR_P(value)) == FAILURE) {
+ /* This should be unreachable in practice. */
+ zend_throw_exception(php_uri_ce_error, "Failed to restore the query parameters", 0);
+ RETURN_THROWS();
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ return;
+
+invalid_data:
+ zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %pS object", uri_query_params_object->std.ce->name);
+ RETURN_THROWS();
+}
+
+PHP_METHOD(Uri_QueryParams, __unserialize)
+{
+ uri_query_params_unserialize(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+
+PHP_METHOD(Uri_QueryParams, __debugInfo)
+{
+ ZEND_PARSE_PARAMETERS_NONE();
+
+ php_uri_query_params_object *uri_query_params_object = Z_URI_QUERY_PARAMS_OBJECT_P(ZEND_THIS);
+
+ RETURN_ARR(php_uri_query_params_get_debug_properties(uri_query_params_object));
+}
diff --git a/ext/uri/php_uri_query.h b/ext/uri/php_uri_query.h
new file mode 100644
index 000000000000..feb566431f98
--- /dev/null
+++ b/ext/uri/php_uri_query.h
@@ -0,0 +1,45 @@
+/*
+ +----------------------------------------------------------------------+
+ | Copyright © The PHP Group and Contributors. |
+ +----------------------------------------------------------------------+
+ | This source file is subject to the Modified BSD License that is |
+ | bundled with this package in the file LICENSE, and is available |
+ | through the World Wide Web at . |
+ | |
+ | SPDX-License-Identifier: BSD-3-Clause |
+ +----------------------------------------------------------------------+
+ | Authors: Máté Kocsis |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHP_URI_QUERY_H
+#define PHP_URI_QUERY_H
+
+#define PHP_URI_QUERY_PARAMS_DEFAULT_MAX_PARAM_COUNT 1000
+
+#define php_uri_query_params_object_from_obj(object) ZEND_CONTAINER_OF(object, php_uri_query_params_object, std)
+
+#define Z_URI_QUERY_PARAMS_OBJECT_P(zv) php_uri_query_params_object_from_obj(Z_OBJ_P((zv)))
+
+typedef enum php_uri_query_params_parsing_method {
+ PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC1866,
+ PHP_URI_QUERY_PARAMS_PARSING_METHOD_RFC3986,
+ PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL,
+ PHP_URI_QUERY_PARAMS_PARSING_METHOD_WHATWG_URL_SEARCH_PARAMS,
+} php_uri_query_params_parsing_method;
+
+ZEND_ATTRIBUTE_NONNULL_ARGS(1, 3) zend_result php_uri_query_params_parse(
+ const char *query_str_first, size_t query_str_length, php_uri_query_params_object *query_params_object,
+ php_uri_query_params_parsing_method parsing_method, bool silent, zend_long max_param_count
+);
+
+ZEND_ATTRIBUTE_NONNULL zend_object *php_uri_object_query_params_create_object(zend_class_entry *ce);
+ZEND_ATTRIBUTE_NONNULL void php_uri_query_params_object_free(php_uri_query_params_object *uri_query_params_object);
+ZEND_ATTRIBUTE_NONNULL void php_uri_query_params_object_handler_free(zend_object *object);
+ZEND_ATTRIBUTE_NONNULL zend_object *php_uri_query_params_object_handler_clone(zend_object *object);
+ZEND_ATTRIBUTE_NONNULL zend_object_iterator *php_uri_object_query_params_get_iterator(zend_class_entry *ce, zval *object, int by_ref);
+
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_query_params_to_rfc3986_string(const php_uri_query_params_object *object);
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_query_params_to_whatwg_string(const php_uri_query_params_object *object);
+
+#endif
diff --git a/ext/uri/tests/query_params/append_error_array.phpt b/ext/uri/tests/query_params/append_error_array.phpt
new file mode 100644
index 000000000000..c8bd7c8b4d4b
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_array.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::append() - error - arrays use the array API
+--FILE--
+append("k", [1, 2]);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::append(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, array given
diff --git a/ext/uri/tests/query_params/append_error_bool.phpt b/ext/uri/tests/query_params/append_error_bool.phpt
new file mode 100644
index 000000000000..9fd291f3b172
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_bool.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::append() - error - boolean value with strict types
+--FILE--
+append("x", true);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::append(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, true given
diff --git a/ext/uri/tests/query_params/append_error_enum_unbacked.phpt b/ext/uri/tests/query_params/append_error_enum_unbacked.phpt
new file mode 100644
index 000000000000..7794d0d96f1c
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_enum_unbacked.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::append() - error - unbacked enum
+--FILE--
+append("foo", TestEnum::Bar);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::append(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, TestEnum given
diff --git a/ext/uri/tests/query_params/append_error_float_infinite.phpt b/ext/uri/tests/query_params/append_error_float_infinite.phpt
new file mode 100644
index 000000000000..eba6611528f3
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_float_infinite.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::append() - error - positive infinity
+--FILE--
+append("x", INF);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params1->count());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::append(): Argument #2 ($value) must be finite
+int(0)
diff --git a/ext/uri/tests/query_params/append_error_float_nan.phpt b/ext/uri/tests/query_params/append_error_float_nan.phpt
new file mode 100644
index 000000000000..82d11f0de2ef
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_float_nan.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::append() - error - NAN
+--FILE--
+append("x", NAN);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params1->count());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::append(): Argument #2 ($value) must be finite
+int(0)
diff --git a/ext/uri/tests/query_params/append_error_float_negative_infinite.phpt b/ext/uri/tests/query_params/append_error_float_negative_infinite.phpt
new file mode 100644
index 000000000000..593be7f86e50
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_float_negative_infinite.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::append() - error - negative infinity
+--FILE--
+append("x", -INF);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params1->count());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::append(): Argument #2 ($value) must be finite
+int(0)
diff --git a/ext/uri/tests/query_params/append_error_object.phpt b/ext/uri/tests/query_params/append_error_object.phpt
new file mode 100644
index 000000000000..560adf04525b
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_object.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::append() - error - object
+--FILE--
+append("foo", new stdClass());
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::append(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, stdClass given
diff --git a/ext/uri/tests/query_params/append_error_resource.phpt b/ext/uri/tests/query_params/append_error_resource.phpt
new file mode 100644
index 000000000000..515b7bf9980f
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_resource.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::append() - error - resource
+--FILE--
+append("foo", fopen("php://memory", "r"));
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::append(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, resource given
diff --git a/ext/uri/tests/query_params/append_error_stringable_destructor.phpt b/ext/uri/tests/query_params/append_error_stringable_destructor.phpt
new file mode 100644
index 000000000000..af105420208c
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_stringable_destructor.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::append() - error - exception during Stringable local variable cleanup
+--INI--
+report_memleaks=1
+--FILE--
+append("key", new Value());
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params->count());
+
+?>
+--EXPECT--
+Exception: Local destructor
+int(0)
diff --git a/ext/uri/tests/query_params/append_error_stringable_exception.phpt b/ext/uri/tests/query_params/append_error_stringable_exception.phpt
new file mode 100644
index 000000000000..6b52b400d3e5
--- /dev/null
+++ b/ext/uri/tests/query_params/append_error_stringable_exception.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::append() - error - Stringable exception is propagated
+--FILE--
+append("a", $value);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($value instanceof Value);
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+Exception: Conversion failed
+bool(true)
+string(3) "a=1"
diff --git a/ext/uri/tests/query_params/append_success_basic.phpt b/ext/uri/tests/query_params/append_success_basic.phpt
new file mode 100644
index 000000000000..e999c59fd116
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_basic.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::append() - success - basic
+--FILE--
+append("baz", "qux");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "baz"
+ [1]=>
+ string(3) "qux"
+ }
+}
+string(23) "abc=123&foo=bar&baz=qux"
+string(23) "abc=123&foo=bar&baz=qux"
+string(23) "abc=123&foo=bar&baz=qux"
diff --git a/ext/uri/tests/query_params/append_success_delimiters.phpt b/ext/uri/tests/query_params/append_success_delimiters.phpt
new file mode 100644
index 000000000000..030254eca38d
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_delimiters.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test Uri\QueryParams::append() - success - delimiters in names and values
+--FILE--
+append("&a=b&", "=c&d=")->append("x", "%26");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "&a=b&"
+ [1]=>
+ string(5) "=c&d="
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(3) "%26"
+ }
+}
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
diff --git a/ext/uri/tests/query_params/append_success_empty_name.phpt b/ext/uri/tests/query_params/append_success_empty_name.phpt
new file mode 100644
index 000000000000..828a096ed2d6
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_empty_name.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Test Uri\QueryParams::append() - success - empty names with null, empty, and non-empty values
+--FILE--
+append("", null)->append("", "")->append("", "bar")->append("", null);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(0) ""
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(3) "bar"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+}
+string(8) "&=&=bar&"
+string(8) "&=&=bar&"
+string(6) "=&=bar"
diff --git a/ext/uri/tests/query_params/append_success_enum_backed.phpt b/ext/uri/tests/query_params/append_success_enum_backed.phpt
new file mode 100644
index 000000000000..36a3729b7873
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_enum_backed.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test Uri\QueryParams::append() - success - backed enum
+--FILE--
+append("foo", StringEnum::Bar);
+$params = $params->append("baz", IntEnum::Baz);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "baz"
+ [1]=>
+ string(3) "123"
+ }
+}
+string(15) "foo=bar&baz=123"
+string(15) "foo=bar&baz=123"
+string(15) "foo=bar&baz=123"
diff --git a/ext/uri/tests/query_params/append_success_existing.phpt b/ext/uri/tests/query_params/append_success_existing.phpt
new file mode 100644
index 000000000000..126d2819049e
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_existing.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::append() - success - existing parameter
+--FILE--
+append("foo", "bar");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(23) "abc=123&foo=bar&foo=bar"
+string(23) "abc=123&foo=bar&foo=bar"
+string(23) "abc=123&foo=bar&foo=bar"
diff --git a/ext/uri/tests/query_params/append_success_float_precision.phpt b/ext/uri/tests/query_params/append_success_float_precision.phpt
new file mode 100644
index 000000000000..48027deabde5
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_float_precision.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Test Uri\QueryParams::append() - success - preserve float precision
+--INI--
+precision=3
+serialize_precision=-1
+--FILE--
+append("x", $value);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+var_dump(floatval($params->getFirst("x")) === $value);
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(18) "1.2345678901234567"
+ }
+}
+string(20) "x=1.2345678901234567"
+string(20) "x=1.2345678901234567"
+string(20) "x=1.2345678901234567"
+bool(true)
diff --git a/ext/uri/tests/query_params/append_success_float_precision_zero.phpt b/ext/uri/tests/query_params/append_success_float_precision_zero.phpt
new file mode 100644
index 000000000000..a87c54fad4d6
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_float_precision_zero.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test Uri\QueryParams::append() - success - zero serialize_precision
+--INI--
+serialize_precision=0
+--FILE--
+append("x", 1.2345);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(6) "1.0e+0"
+ }
+}
+string(10) "x=1.0e%2B0"
+string(8) "x=1.0e+0"
+string(10) "x=1.0e%2B0"
diff --git a/ext/uri/tests/query_params/append_success_float_scientific_notation.phpt b/ext/uri/tests/query_params/append_success_float_scientific_notation.phpt
new file mode 100644
index 000000000000..0303d275a8fc
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_float_scientific_notation.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test Uri\QueryParams::append() - success - scientific notation of floats
+--INI--
+precision=3
+serialize_precision=-1
+--FILE--
+append("small", 1e-10)->append("large", 1e20)->append("integer", 1e14);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+var_dump(floatval($params->getFirst("small")) === 1e-10);
+var_dump(floatval($params->getFirst("large")) === 1e20);
+var_dump(floatval($params->getFirst("integer")) === 1e14);
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "small"
+ [1]=>
+ string(7) "1.0e-10"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(5) "large"
+ [1]=>
+ string(7) "1.0e+20"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(7) "integer"
+ [1]=>
+ string(15) "100000000000000"
+ }
+}
+string(53) "small=1.0e-10&large=1.0e%2B20&integer=100000000000000"
+string(51) "small=1.0e-10&large=1.0e+20&integer=100000000000000"
+string(53) "small=1.0e-10&large=1.0e%2B20&integer=100000000000000"
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/uri/tests/query_params/append_success_immutable.phpt b/ext/uri/tests/query_params/append_success_immutable.phpt
new file mode 100644
index 000000000000..cd06912532e2
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_immutable.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Test Uri\QueryParams::append() - success - the original instance is unchanged
+--FILE--
+append("x", "3");
+
+var_dump($params1 === $params2);
+var_dump($params1->toRfc3986String());
+var_dump($params1->getLast("x"));
+var_dump($params2->toList());
+var_dump($params2->toRfc1866String());
+var_dump($params2->toRfc3986String());
+var_dump($params2->toWhatWgUrlString());
+
+?>
+--EXPECT--
+bool(false)
+string(12) "x=1&x=2&flag"
+string(1) "2"
+array(4) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "2"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(4) "flag"
+ [1]=>
+ NULL
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "3"
+ }
+}
+string(16) "x=1&x=2&flag&x=3"
+string(16) "x=1&x=2&flag&x=3"
+string(16) "x=1&x=2&flag&x=3"
diff --git a/ext/uri/tests/query_params/append_success_int.phpt b/ext/uri/tests/query_params/append_success_int.phpt
new file mode 100644
index 000000000000..6a3c339fda3d
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_int.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test Uri\QueryParams::append() - success - integer value
+
+--FILE--
+append("baz", 0);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "baz"
+ [1]=>
+ string(1) "0"
+ }
+}
+string(21) "abc=123&foo=bar&baz=0"
+string(21) "abc=123&foo=bar&baz=0"
+string(21) "abc=123&foo=bar&baz=0"
diff --git a/ext/uri/tests/query_params/append_success_line_breaks.phpt b/ext/uri/tests/query_params/append_success_line_breaks.phpt
new file mode 100644
index 000000000000..829d31309e3b
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_line_breaks.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::append() - success - LF, CR, and CRLF in names and values
+--FILE--
+append("a\nb\rc\r\nd", "e\nf\rg\r\nh");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(8) "a%r\n%rb%r\r%rc%r\r?\n%rd"
+ [1]=>
+ string(8) "e%r\n%rf%r\r%rg%r\r?\n%rh"
+ }
+}
+string(45) "a%r\x25%r0D%r\x25%r0Ab%r\x25%r0D%r\x25%r0Ac%r\x25%r0D%r\x25%r0Ad=e%r\x25%r0D%r\x25%r0Af%r\x25%r0D%r\x25%r0Ag%r\x25%r0D%r\x25%r0Ah"
+string(33) "a%r\x25%r0Ab%r\x25%r0Dc%r\x25%r0D%r\x25%r0Ad=e%r\x25%r0Af%r\x25%r0Dg%r\x25%r0D%r\x25%r0Ah"
+string(33) "a%r\x25%r0Ab%r\x25%r0Dc%r\x25%r0D%r\x25%r0Ad=e%r\x25%r0Af%r\x25%r0Dg%r\x25%r0D%r\x25%r0Ah"
diff --git a/ext/uri/tests/query_params/append_success_non_finite_strings.phpt b/ext/uri/tests/query_params/append_success_non_finite_strings.phpt
new file mode 100644
index 000000000000..3716a6507c75
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_non_finite_strings.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::append() - success - strings representing non-finite floats
+--FILE--
+append("positive", "INF")->append("negative", "-INF")->append("nan", "NAN");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(8) "positive"
+ [1]=>
+ string(3) "INF"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(8) "negative"
+ [1]=>
+ string(4) "-INF"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "nan"
+ [1]=>
+ string(3) "NAN"
+ }
+}
+string(34) "positive=INF&negative=-INF&nan=NAN"
+string(34) "positive=INF&negative=-INF&nan=NAN"
+string(34) "positive=INF&negative=-INF&nan=NAN"
diff --git a/ext/uri/tests/query_params/append_success_nul_byte.phpt b/ext/uri/tests/query_params/append_success_nul_byte.phpt
new file mode 100644
index 000000000000..c057369cdb26
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_nul_byte.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::append() - success - contains NUL bytes
+--FILE--
+append("a\0b", "c\0d");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a%0b"
+ [1]=>
+ string(3) "c%0d"
+ }
+}
+string(11) "a%r\x25%r00b=c%r\x25%r00d"
+string(11) "a%r\x25%r00b=c%r\x25%r00d"
+string(11) "a%r\x25%r00b=c%r\x25%r00d"
diff --git a/ext/uri/tests/query_params/append_success_null.phpt b/ext/uri/tests/query_params/append_success_null.phpt
new file mode 100644
index 000000000000..37b2e6afaf1c
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_null.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::append() - success - null value
+--FILE--
+append("baz", null);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "baz"
+ [1]=>
+ NULL
+ }
+}
+string(19) "abc=123&foo=bar&baz"
+string(19) "abc=123&foo=bar&baz"
+string(19) "abc=123&foo=bar&baz"
diff --git a/ext/uri/tests/query_params/append_success_percent_encoding.phpt b/ext/uri/tests/query_params/append_success_percent_encoding.phpt
new file mode 100644
index 000000000000..9c406fecfbbf
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_percent_encoding.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test Uri\QueryParams::append() - success - percent-encoding names and values
+--FILE--
+append("a c", "#123")->append("", "b@r~*");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a c"
+ [1]=>
+ string(4) "#123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(5) ""
+ [1]=>
+ string(5) "b@r~*"
+ }
+}
+string(30) "a+c=%23123&%3Cfoo%3E=b%40r~%2A"
+string(28) "a%20c=%23123&%3Cfoo%3E=b@r~*"
+string(30) "a+c=%23123&%3Cfoo%3E=b%40r%7E*"
diff --git a/ext/uri/tests/query_params/append_success_temporary.phpt b/ext/uri/tests/query_params/append_success_temporary.phpt
new file mode 100644
index 000000000000..df3a5875a838
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_temporary.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::append() - success - an unshared temporary instance is reused
+--FILE--
+append("x", "2");
+
+var_dump(spl_object_id($params) === $id);
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "2"
+ }
+}
+string(7) "x=1&x=2"
+string(7) "x=1&x=2"
+string(7) "x=1&x=2"
diff --git a/ext/uri/tests/query_params/append_success_utf8_incomplete.phpt b/ext/uri/tests/query_params/append_success_utf8_incomplete.phpt
new file mode 100644
index 000000000000..61b10e494950
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_utf8_incomplete.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::append() - success - incomplete UTF-8 sequence
+--FILE--
+append("a\xE2\x82", "a\xE2\x82");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a%r\xE2\x82%r"
+ [1]=>
+ string(3) "a%r\xE2\x82%r"
+ }
+}
+string(15) "a%E2%82=a%E2%82"
+string(15) "a%E2%82=a%E2%82"
+string(21) "a%EF%BF%BD=a%EF%BF%BD"
diff --git a/ext/uri/tests/query_params/append_success_utf8_invalid.phpt b/ext/uri/tests/query_params/append_success_utf8_invalid.phpt
new file mode 100644
index 000000000000..e14d67847662
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_utf8_invalid.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::append() - success - invalid UTF-8 byte
+--FILE--
+append("a\xFFz", "a\xFFz");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a%r\xFF%rz"
+ [1]=>
+ string(3) "a%r\xFF%rz"
+ }
+}
+string(11) "a%FFz=a%FFz"
+string(11) "a%FFz=a%FFz"
+string(23) "a%EF%BF%BDz=a%EF%BF%BDz"
diff --git a/ext/uri/tests/query_params/append_success_utf8_valid.phpt b/ext/uri/tests/query_params/append_success_utf8_valid.phpt
new file mode 100644
index 000000000000..65de226ab1ef
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_utf8_valid.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::append() - success - valid two-, three-, and four-byte UTF-8 sequences
+--FILE--
+append("aé€😀z", "bé€😀y");
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(11) "aé€😀z"
+ [1]=>
+ string(11) "bé€😀y"
+ }
+}
+string(59) "a%C3%A9%E2%82%AC%F0%9F%98%80z=b%C3%A9%E2%82%AC%F0%9F%98%80y"
+string(59) "a%C3%A9%E2%82%AC%F0%9F%98%80z=b%C3%A9%E2%82%AC%F0%9F%98%80y"
+string(59) "a%C3%A9%E2%82%AC%F0%9F%98%80z=b%C3%A9%E2%82%AC%F0%9F%98%80y"
diff --git a/ext/uri/tests/query_params/append_success_weak_map.phpt b/ext/uri/tests/query_params/append_success_weak_map.phpt
new file mode 100644
index 000000000000..715c2f104e23
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_weak_map.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test Uri\QueryParams::append() - success - a temporary instance used as a WeakMap key is cloned
+--FILE--
+append("x", "2");
+
+var_dump(count($map));
+var_dump(isset($map[$params]));
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+int(0)
+bool(false)
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "2"
+ }
+}
+string(7) "x=1&x=2"
+string(7) "x=1&x=2"
+string(7) "x=1&x=2"
diff --git a/ext/uri/tests/query_params/append_success_weak_reference.phpt b/ext/uri/tests/query_params/append_success_weak_reference.phpt
new file mode 100644
index 000000000000..ee83f32a2fbe
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_weak_reference.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::append() - success - a weakly referenced temporary instance is cloned
+--FILE--
+append("x", "2");
+
+var_dump($reference->get());
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+NULL
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "2"
+ }
+}
+string(7) "x=1&x=2"
+string(7) "x=1&x=2"
+string(7) "x=1&x=2"
diff --git a/ext/uri/tests/query_params/append_success_weak_types.phpt b/ext/uri/tests/query_params/append_success_weak_types.phpt
new file mode 100644
index 000000000000..46a6db2d829f
--- /dev/null
+++ b/ext/uri/tests/query_params/append_success_weak_types.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Test Uri\QueryParams::append() - success - weak boolean and Stringable conversion
+--FILE--
+append("a", false)->append("b", true)->append("c", $reference);
+
+var_dump($value instanceof Value);
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+bool(true)
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "0"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(1) "1"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(1) "c"
+ [1]=>
+ string(4) "0012"
+ }
+}
+string(14) "a=0&b=1&c=0012"
+string(14) "a=0&b=1&c=0012"
+string(14) "a=0&b=1&c=0012"
diff --git a/ext/uri/tests/query_params/clone_success_empty.phpt b/ext/uri/tests/query_params/clone_success_empty.phpt
new file mode 100644
index 000000000000..d6dea7a80db3
--- /dev/null
+++ b/ext/uri/tests/query_params/clone_success_empty.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams cloning - success - empty instance
+--FILE--
+append("x", "1");
+var_dump($params2->toRfc3986String());
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+string(3) "x=1"
+int(1)
diff --git a/ext/uri/tests/query_params/clone_success_tombstones.phpt b/ext/uri/tests/query_params/clone_success_tombstones.phpt
new file mode 100644
index 000000000000..62816bc2c07e
--- /dev/null
+++ b/ext/uri/tests/query_params/clone_success_tombstones.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test Uri\QueryParams cloning - success - deleted entries and null values
+--FILE--
+deleteValue("x", "1");
+$params2 = clone $params1;
+
+var_dump($params1 === $params2);
+
+unset($params1);
+var_dump($params2->toRfc3986String());
+var_dump($params2->getFirst("x"));
+var_dump($params2->getLast("x"));
+var_dump($params2->count());
+
+$params2 = $params2->append("x", "3");
+var_dump($params2->toRfc3986String());
+var_dump($params2->getLast("x"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+string(8) "x=2&flag"
+string(1) "2"
+string(1) "2"
+int(2)
+string(12) "x=2&flag&x=3"
+string(1) "3"
+int(3)
diff --git a/ext/uri/tests/query_params/construct_error_reinitialization.phpt b/ext/uri/tests/query_params/construct_error_reinitialization.phpt
new file mode 100644
index 000000000000..920712ce8adb
--- /dev/null
+++ b/ext/uri/tests/query_params/construct_error_reinitialization.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::__construct() - error - reinitialization
+--FILE--
+__construct();
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+Error: Cannot modify readonly object of class Uri\QueryParams
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/construct_success_basic.phpt b/ext/uri/tests/query_params/construct_success_basic.phpt
new file mode 100644
index 000000000000..dc25e1c68dfa
--- /dev/null
+++ b/ext/uri/tests/query_params/construct_success_basic.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::__construct() - success - basic
+--FILE--
+toRfc3986String());
+
+?>
+--EXPECTF--
+object(Uri\QueryParams)#%d (%d) {
+ ["params"]=>
+ array(0) {
+ }
+}
+string(0) ""
diff --git a/ext/uri/tests/query_params/delete_success_compaction_empty.phpt b/ext/uri/tests/query_params/delete_success_compaction_empty.phpt
new file mode 100644
index 000000000000..bb216cbc596d
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_success_compaction_empty.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Test Uri\QueryParams::delete() - success - compacting a fully deleted list
+--FILE--
+delete("x");
+
+var_dump($params1->count());
+var_dump($params2->toList());
+var_dump(iterator_to_array($params2));
+var_dump($params2->count());
+var_dump($params2->has("x"));
+
+$params2 = $params2->append("x", "2")->append("x", "3");
+var_dump($params2->toRfc3986String());
+var_dump($params2->count());
+var_dump($params2->getAll("x"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+?>
+--EXPECT--
+int(101)
+array(0) {
+}
+array(0) {
+}
+int(0)
+bool(false)
+string(7) "x=2&x=3"
+int(2)
+array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(1) "3"
+}
+bool(true)
diff --git a/ext/uri/tests/query_params/delete_success_compaction_immutable.phpt b/ext/uri/tests/query_params/delete_success_compaction_immutable.phpt
new file mode 100644
index 000000000000..9333f5a9aeca
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_success_compaction_immutable.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Test Uri\QueryParams::delete() - success - compacting deleted entries preserves both instances
+--FILE--
+delete("x");
+
+var_dump($params1->toRfc3986String() === $query);
+var_dump($params1->count());
+var_dump($params1->getLast("x"));
+var_dump($params2->toRfc3986String());
+var_dump($params2->count());
+var_dump($params2->getFirst("y"));
+var_dump($params2->getLast("y"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+$params2 = $params2->append("y", "4");
+var_dump($params2->toRfc3986String());
+var_dump($params2->count());
+var_dump($params2->getLast("y"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+?>
+--EXPECT--
+bool(true)
+int(104)
+string(1) "1"
+string(12) "y=2&y=3&flag"
+int(3)
+string(1) "2"
+string(1) "3"
+bool(true)
+string(16) "y=2&y=3&flag&y=4"
+int(4)
+string(1) "4"
+bool(true)
diff --git a/ext/uri/tests/query_params/delete_success_compaction_interleaved.phpt b/ext/uri/tests/query_params/delete_success_compaction_interleaved.phpt
new file mode 100644
index 000000000000..2106fd24a46e
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_success_compaction_interleaved.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Test Uri\QueryParams::delete() - success - compacting interleaved entries and compacting again
+--FILE--
+delete("x");
+
+var_dump($params1->toRfc3986String() === $query);
+var_dump($params2->toRfc3986String() === "y=first&" . str_repeat("y=middle&", 100) . "flag&y=last");
+var_dump($params2->count());
+var_dump($params2->has("x"));
+var_dump($params2->getFirst("y"));
+var_dump($params2->getLast("y"));
+var_dump($params2->getAll("y") === array_merge(["first"], array_fill(0, 100, "middle"), ["last"]));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+$params2 = $params2->append("y", "appended");
+var_dump($params2->getLast("y"));
+$params2 = $params2->deleteValue("y", "middle");
+var_dump($params2->toRfc3986String());
+
+// Removing the remaining duplicate names triggers compaction a second time.
+$params2 = $params2->set("y", "only");
+var_dump($params2->toRfc3986String());
+var_dump($params2->count());
+var_dump($params2->getFirst("y"));
+var_dump($params2->getLast("y"));
+var_dump($params2->has("flag"));
+var_dump($params2->getFirst("flag"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+int(103)
+bool(false)
+string(5) "first"
+string(4) "last"
+bool(true)
+bool(true)
+string(8) "appended"
+string(30) "y=first&flag&y=last&y=appended"
+string(11) "y=only&flag"
+int(2)
+string(4) "only"
+string(4) "only"
+bool(true)
+NULL
+bool(true)
diff --git a/ext/uri/tests/query_params/delete_success_existing.phpt b/ext/uri/tests/query_params/delete_success_existing.phpt
new file mode 100644
index 000000000000..cda429216116
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_success_existing.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::delete() - success - basic
+--FILE--
+delete("abc");
+$params = $params->delete("foo");
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
diff --git a/ext/uri/tests/query_params/delete_success_immutable.phpt b/ext/uri/tests/query_params/delete_success_immutable.phpt
new file mode 100644
index 000000000000..a25bf7d5d487
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_success_immutable.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test Uri\QueryParams::delete() - success - the original instance is unchanged
+--FILE--
+delete("x");
+
+var_dump($params1 === $params2);
+var_dump($params1->toRfc3986String());
+var_dump($params1->getFirst("x"));
+var_dump($params1->getLast("x"));
+var_dump($params2->toRfc3986String());
+var_dump($params2->has("x"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+string(12) "x=1&x=2&flag"
+string(1) "1"
+string(1) "2"
+string(4) "flag"
+bool(false)
+int(1)
diff --git a/ext/uri/tests/query_params/delete_success_multiple.phpt b/ext/uri/tests/query_params/delete_success_multiple.phpt
new file mode 100644
index 000000000000..c40fd81b6b5f
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_success_multiple.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test Uri\QueryParams::delete() - success - multiple values
+--FILE--
+delete("abc");
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(7) "foo=bar"
diff --git a/ext/uri/tests/query_params/delete_success_non_existent.phpt b/ext/uri/tests/query_params/delete_success_non_existent.phpt
new file mode 100644
index 000000000000..9274567b2734
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_success_non_existent.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test Uri\QueryParams::delete() - success - non-existent key
+--FILE--
+delete("xyz");
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(15) "abc=123&foo=bar"
diff --git a/ext/uri/tests/query_params/delete_value_error_array.phpt b/ext/uri/tests/query_params/delete_value_error_array.phpt
new file mode 100644
index 000000000000..e94142ac87a6
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_error_array.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - error - array value for a missing key
+--FILE--
+deleteValue("missing", ["1"]);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::deleteValue(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, array given
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/delete_value_error_bool.phpt b/ext/uri/tests/query_params/delete_value_error_bool.phpt
new file mode 100644
index 000000000000..728bb6dbb231
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_error_bool.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - error - boolean value with strict types
+--FILE--
+deleteValue("x", false);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::deleteValue(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, false given
diff --git a/ext/uri/tests/query_params/delete_value_error_enum_unbacked.phpt b/ext/uri/tests/query_params/delete_value_error_enum_unbacked.phpt
new file mode 100644
index 000000000000..6dacc50d0b1c
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_error_enum_unbacked.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - error - enum unbacked
+--FILE--
+deleteValue("x", Flag::Enabled);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::deleteValue(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, Flag given
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/delete_value_error_float_non_finite.phpt b/ext/uri/tests/query_params/delete_value_error_float_non_finite.phpt
new file mode 100644
index 000000000000..718bfef1ac21
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_error_float_non_finite.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - error - non-finite float leaves the original unchanged
+--FILE--
+append("x", "-INF");
+
+try {
+ $params2 = $params1->deleteValue("x", -INF);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params1->toRfc3986String());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::deleteValue(): Argument #2 ($value) must be finite
+string(6) "x=-INF"
diff --git a/ext/uri/tests/query_params/delete_value_error_resource.phpt b/ext/uri/tests/query_params/delete_value_error_resource.phpt
new file mode 100644
index 000000000000..00a3bf7b08ca
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_error_resource.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - error - resource
+--FILE--
+deleteValue("x", $value);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::deleteValue(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, resource given
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/delete_value_error_stringable.phpt b/ext/uri/tests/query_params/delete_value_error_stringable.phpt
new file mode 100644
index 000000000000..42d2354ce68a
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_error_stringable.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - error - stringable with strict types
+--FILE--
+deleteValue("x", $value);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::deleteValue(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, C given
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/delete_value_success_enum_backed.phpt b/ext/uri/tests/query_params/delete_value_success_enum_backed.phpt
new file mode 100644
index 000000000000..a8cfdb18dbd7
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_enum_backed.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - string and integer backed enums
+--FILE--
+deleteValue("foo", StringEnum::Bar)->deleteValue("baz", IntEnum::Baz);
+
+var_dump($params1->toRfc3986String());
+var_dump($params2->toRfc3986String());
+
+?>
+--EXPECT--
+string(24) "foo=bar&baz=123&keep=yes"
+string(8) "keep=yes"
diff --git a/ext/uri/tests/query_params/delete_value_success_existing_key_missing_value.phpt b/ext/uri/tests/query_params/delete_value_success_existing_key_missing_value.phpt
new file mode 100644
index 000000000000..23b12d7b7316
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_existing_key_missing_value.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - existing key, missing value
+--FILE--
+deleteValue("abc", "");
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "456"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ NULL
+ }
+}
+string(19) "abc=123&abc=456&abc"
diff --git a/ext/uri/tests/query_params/delete_value_success_existing_key_value.phpt b/ext/uri/tests/query_params/delete_value_success_existing_key_value.phpt
new file mode 100644
index 000000000000..34c3189fd100
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_existing_key_value.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - existing key, existing value
+--FILE--
+deleteValue("abc", 456);
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "789"
+ }
+}
+string(15) "abc=123&abc=789"
diff --git a/ext/uri/tests/query_params/delete_value_success_immutable.phpt b/ext/uri/tests/query_params/delete_value_success_immutable.phpt
new file mode 100644
index 000000000000..8b7bf10a7b29
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_immutable.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - the original instance is unchanged
+--FILE--
+deleteValue("x", "1");
+
+var_dump($params1 === $params2);
+var_dump($params1->toRfc3986String());
+var_dump($params1->getFirst("x"));
+var_dump($params1->getLast("x"));
+var_dump($params2->toRfc3986String());
+var_dump($params2->getFirst("x"));
+var_dump($params2->getLast("x"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+string(16) "x=1&x=2&x=1&flag"
+string(1) "1"
+string(1) "1"
+string(8) "x=2&flag"
+string(1) "2"
+string(1) "2"
+int(2)
diff --git a/ext/uri/tests/query_params/delete_value_success_int.phpt b/ext/uri/tests/query_params/delete_value_success_int.phpt
new file mode 100644
index 000000000000..29773c2d538f
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_int.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - int value
+--FILE--
+deleteValue("abc", 123);
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "456"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "foo"
+ }
+}
+string(15) "abc=456&abc=foo"
diff --git a/ext/uri/tests/query_params/delete_value_success_later_match_immutable.phpt b/ext/uri/tests/query_params/delete_value_success_later_match_immutable.phpt
new file mode 100644
index 000000000000..2de10c1bb01b
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_later_match_immutable.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - deleting later matching values leaves the original instance unchanged
+--FILE--
+deleteValue("x", "2");
+
+var_dump($params1 === $params2);
+var_dump($params1->toRfc3986String());
+var_dump($params1->getAll("x"));
+var_dump($params2->toRfc3986String());
+var_dump($params2->getAll("x"));
+var_dump($params2->getFirst("x"));
+var_dump($params2->getLast("x"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+string(26) "x=1&other=keep&x=2&x=3&x=2"
+array(4) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+ [2]=>
+ string(1) "3"
+ [3]=>
+ string(1) "2"
+}
+string(18) "x=1&other=keep&x=3"
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "3"
+}
+string(1) "1"
+string(1) "3"
+int(3)
diff --git a/ext/uri/tests/query_params/delete_value_success_missing_key.phpt b/ext/uri/tests/query_params/delete_value_success_missing_key.phpt
new file mode 100644
index 000000000000..d55d5dab19e1
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_missing_key.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - missing key
+--FILE--
+deleteValue("def", 456);
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "456"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "789"
+ }
+}
+string(23) "abc=123&abc=456&abc=789"
diff --git a/ext/uri/tests/query_params/delete_value_success_null.phpt b/ext/uri/tests/query_params/delete_value_success_null.phpt
new file mode 100644
index 000000000000..372f7b974295
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_null.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - null value
+--FILE--
+deleteValue("abc", null);
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "456"
+ }
+}
+string(15) "abc=123&abc=456"
diff --git a/ext/uri/tests/query_params/delete_value_success_strict_types.phpt b/ext/uri/tests/query_params/delete_value_success_strict_types.phpt
new file mode 100644
index 000000000000..8cb2b69c411d
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_strict_types.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - scalar conversion with strict types
+--FILE--
+deleteValue("int", 123)->deleteValue("float", 1.25);
+
+var_dump($params1->toRfc3986String());
+var_dump($params2->toRfc3986String());
+
+?>
+--EXPECT--
+string(27) "int=123&float=1.25&keep=yes"
+string(8) "keep=yes"
diff --git a/ext/uri/tests/query_params/delete_value_success_temporary.phpt b/ext/uri/tests/query_params/delete_value_success_temporary.phpt
new file mode 100644
index 000000000000..4947d618c117
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_temporary.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - later matching value in a temporary instance
+--FILE--
+deleteValue("x", "2");
+
+var_dump($params->getAll("x"));
+var_dump($params->getFirst("x"));
+var_dump($params->getLast("x"));
+var_dump($params->count());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "3"
+}
+string(1) "1"
+string(1) "3"
+int(2)
+string(7) "x=1&x=3"
diff --git a/ext/uri/tests/query_params/delete_value_success_weak_types.phpt b/ext/uri/tests/query_params/delete_value_success_weak_types.phpt
new file mode 100644
index 000000000000..e7798ae67766
--- /dev/null
+++ b/ext/uri/tests/query_params/delete_value_success_weak_types.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::deleteValue() - success - weak boolean and Stringable conversion
+--FILE--
+deleteValue("a", false)->deleteValue("a", true)->deleteValue("a", new Value());
+
+var_dump($params1->toRfc3986String());
+var_dump($params2->getAll("a"));
+
+?>
+--EXPECT--
+string(19) "a=0&a=1&a=0012&a=&a"
+array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+}
diff --git a/ext/uri/tests/query_params/from_array_error_bool.phpt b/ext/uri/tests/query_params/from_array_error_bool.phpt
new file mode 100644
index 000000000000..10d18881a73b
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_error_bool.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - error - nested boolean
+--FILE--
+ [false]]);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::fromArray(): Argument #1 ($queryParams) contains an invalid value for query parameter "nested[]": expected BackedEnum|string|int|float|null, false given
diff --git a/ext/uri/tests/query_params/from_array_error_enum_unbacked.phpt b/ext/uri/tests/query_params/from_array_error_enum_unbacked.phpt
new file mode 100644
index 000000000000..ecd0c41b69dd
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_error_enum_unbacked.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - error - nested unbacked enum
+--FILE--
+ [TestEnum::Value]]);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::fromArray(): Argument #1 ($queryParams) contains an invalid value for query parameter "nested[]": expected BackedEnum|string|int|float|null, TestEnum given
diff --git a/ext/uri/tests/query_params/from_array_error_float_non_finite.phpt b/ext/uri/tests/query_params/from_array_error_float_non_finite.phpt
new file mode 100644
index 000000000000..44c6addd97c0
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_error_float_non_finite.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - error - nested non-finite float reference
+--FILE--
+ 1, "nested" => [&$value]]);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::fromArray(): Argument #1 ($queryParams) contains a non-finite float for query parameter "nested[]"
diff --git a/ext/uri/tests/query_params/from_array_error_mutual_recursion.phpt b/ext/uri/tests/query_params/from_array_error_mutual_recursion.phpt
new file mode 100644
index 000000000000..d1a7cd841266
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_error_mutual_recursion.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - error - indirect recursion
+--FILE--
+ &$left];
+$left["right"] = &$right;
+
+try {
+ Uri\QueryParams::fromArray($left);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::fromArray(): Argument #1 ($queryParams) must not contain recursive arrays
diff --git a/ext/uri/tests/query_params/from_array_error_object.phpt b/ext/uri/tests/query_params/from_array_error_object.phpt
new file mode 100644
index 000000000000..2a78b8fa45ce
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_error_object.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - error - nested object
+--FILE--
+ [new stdClass()]]);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::fromArray(): Argument #1 ($queryParams) contains an invalid value for query parameter "nested[]": expected BackedEnum|string|int|float|null, stdClass given
diff --git a/ext/uri/tests/query_params/from_array_error_recursive.phpt b/ext/uri/tests/query_params/from_array_error_recursive.phpt
new file mode 100644
index 000000000000..21956ded2f63
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_error_recursive.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - error - recursive input and recovery
+--FILE--
+ 1];
+$array["self"] = &$array;
+
+try {
+ Uri\QueryParams::fromArray($array);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+unset($array["self"]);
+var_dump(Uri\QueryParams::fromArray($array)->toList());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::fromArray(): Argument #1 ($queryParams) must not contain recursive arrays
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "value"
+ [1]=>
+ string(1) "1"
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_error_resource.phpt b/ext/uri/tests/query_params/from_array_error_resource.phpt
new file mode 100644
index 000000000000..a03b953a66a0
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_error_resource.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - error - nested resource
+--FILE--
+ [$resource]]);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+fclose($resource);
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::fromArray(): Argument #1 ($queryParams) contains an invalid value for query parameter "nested[]": expected BackedEnum|string|int|float|null, resource given
diff --git a/ext/uri/tests/query_params/from_array_success_backed_enums.phpt b/ext/uri/tests/query_params/from_array_success_backed_enums.phpt
new file mode 100644
index 000000000000..c9b1d04ae32b
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_backed_enums.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - integer and string backed enums
+--FILE--
+ IntEnum::Value, "string" => StringEnum::Value]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(7) "integer"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(6) "string"
+ [1]=>
+ string(3) "abc"
+ }
+}
+array(2) {
+ ["integer"]=>
+ string(3) "123"
+ ["string"]=>
+ string(3) "abc"
+}
diff --git a/ext/uri/tests/query_params/from_array_success_basic.phpt b/ext/uri/tests/query_params/from_array_success_basic.phpt
new file mode 100644
index 000000000000..1473054fa222
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_basic.phpt
@@ -0,0 +1,63 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - scalar values
+--FILE--
+ "bar", "number" => 123, "float" => 3.5, "flag" => null, "empty" => ""]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(5) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(6) "number"
+ [1]=>
+ string(3) "123"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(5) "float"
+ [1]=>
+ string(3) "3.5"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(4) "flag"
+ [1]=>
+ NULL
+ }
+ [4]=>
+ array(2) {
+ [0]=>
+ string(5) "empty"
+ [1]=>
+ string(0) ""
+ }
+}
+array(5) {
+ ["foo"]=>
+ string(3) "bar"
+ ["number"]=>
+ string(3) "123"
+ ["float"]=>
+ string(3) "3.5"
+ ["flag"]=>
+ NULL
+ ["empty"]=>
+ string(0) ""
+}
+string(40) "foo=bar&number=123&float=3.5&flag&empty="
diff --git a/ext/uri/tests/query_params/from_array_success_deep_array.phpt b/ext/uri/tests/query_params/from_array_success_deep_array.phpt
new file mode 100644
index 000000000000..aad3f84b023e
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_deep_array.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - the toArray nesting limit does not restrict construction
+--FILE--
+ $array];
+}
+$params = Uri\QueryParams::fromArray($array);
+
+var_dump($params->count());
+var_dump($params->getFirst("a" . str_repeat("[a]", 65)));
+var_dump($params->toArray(65) === $array);
+
+?>
+--EXPECT--
+int(1)
+string(5) "value"
+bool(true)
diff --git a/ext/uri/tests/query_params/from_array_success_empty.phpt b/ext/uri/tests/query_params/from_array_success_empty.phpt
new file mode 100644
index 000000000000..f9e01a0bf5db
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_empty.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - empty input
+--FILE--
+toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(0) {
+}
+array(0) {
+}
diff --git a/ext/uri/tests/query_params/from_array_success_empty_arrays.phpt b/ext/uri/tests/query_params/from_array_success_empty_arrays.phpt
new file mode 100644
index 000000000000..2f4b82665651
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_empty_arrays.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - empty arrays are omitted at every level
+--FILE--
+ "bar", "empty" => [], "nested" => ["empty" => []]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+array(1) {
+ ["foo"]=>
+ string(3) "bar"
+}
diff --git a/ext/uri/tests/query_params/from_array_success_float_precision.phpt b/ext/uri/tests/query_params/from_array_success_float_precision.phpt
new file mode 100644
index 000000000000..f66d3340b484
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_float_precision.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - configured serialize_precision
+--INI--
+precision=3
+serialize_precision=5
+--FILE--
+ 1.2345678901234567]);
+
+var_dump($params->toList());
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(6) "1.2346"
+ }
+}
+string(8) "x=1.2346"
diff --git a/ext/uri/tests/query_params/from_array_success_list.phpt b/ext/uri/tests/query_params/from_array_success_list.phpt
new file mode 100644
index 000000000000..58c644fa1d09
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_list.phpt
@@ -0,0 +1,58 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - scalar lists use empty brackets
+--FILE--
+ [1, 2, 3], "single" => [4]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "foo[]"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(5) "foo[]"
+ [1]=>
+ string(1) "2"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(5) "foo[]"
+ [1]=>
+ string(1) "3"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(8) "single[]"
+ [1]=>
+ string(1) "4"
+ }
+}
+array(2) {
+ ["foo"]=>
+ array(3) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+ [2]=>
+ string(1) "3"
+ }
+ ["single"]=>
+ array(1) {
+ [0]=>
+ string(1) "4"
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_success_literal.phpt b/ext/uri/tests/query_params/from_array_success_literal.phpt
new file mode 100644
index 000000000000..9ae0edc0ccbb
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_literal.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - names and values are not percent-decoded
+--FILE--
+ "a%20b", "space name" => "a b"]);
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(9) "foo%5B%5D"
+ [1]=>
+ string(5) "a%20b"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(10) "space name"
+ [1]=>
+ string(3) "a b"
+ }
+}
+string(36) "foo%255B%255D=a%2520b&space+name=a+b"
+string(40) "foo%255B%255D=a%2520b&space%20name=a%20b"
+string(36) "foo%255B%255D=a%2520b&space+name=a+b"
diff --git a/ext/uri/tests/query_params/from_array_success_map.phpt b/ext/uri/tests/query_params/from_array_success_map.phpt
new file mode 100644
index 000000000000..4b2576599352
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_map.phpt
@@ -0,0 +1,76 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - mixed map keys and value types
+--FILE--
+ [null, 0, "key2" => 1, 123, "", ["bla"]]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(6) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(6) "baz[0]"
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(6) "baz[1]"
+ [1]=>
+ string(1) "0"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(9) "baz[key2]"
+ [1]=>
+ string(1) "1"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(6) "baz[2]"
+ [1]=>
+ string(3) "123"
+ }
+ [4]=>
+ array(2) {
+ [0]=>
+ string(6) "baz[3]"
+ [1]=>
+ string(0) ""
+ }
+ [5]=>
+ array(2) {
+ [0]=>
+ string(8) "baz[4][]"
+ [1]=>
+ string(3) "bla"
+ }
+}
+array(1) {
+ ["baz"]=>
+ array(6) {
+ [0]=>
+ NULL
+ [1]=>
+ string(1) "0"
+ ["key2"]=>
+ string(1) "1"
+ [2]=>
+ string(3) "123"
+ [3]=>
+ string(0) ""
+ [4]=>
+ array(1) {
+ [0]=>
+ string(3) "bla"
+ }
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_success_mixed_list.phpt b/ext/uri/tests/query_params/from_array_success_mixed_list.phpt
new file mode 100644
index 000000000000..d9ff6701f716
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_mixed_list.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - a list with an array uses explicit indices for all elements
+--FILE--
+ [1, ["a" => 2], 3]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "k[0]"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(7) "k[1][a]"
+ [1]=>
+ string(1) "2"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(4) "k[2]"
+ [1]=>
+ string(1) "3"
+ }
+}
+array(1) {
+ ["k"]=>
+ array(3) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ array(1) {
+ ["a"]=>
+ string(1) "2"
+ }
+ [2]=>
+ string(1) "3"
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_success_multi_level_list.phpt b/ext/uri/tests/query_params/from_array_success_multi_level_list.phpt
new file mode 100644
index 000000000000..11943790eaa3
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_multi_level_list.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - nested lists retain their grouping
+--FILE--
+ [["bar"], [123]]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(8) "foo[0][]"
+ [1]=>
+ string(3) "bar"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(8) "foo[1][]"
+ [1]=>
+ string(3) "123"
+ }
+}
+array(1) {
+ ["foo"]=>
+ array(2) {
+ [0]=>
+ array(1) {
+ [0]=>
+ string(3) "bar"
+ }
+ [1]=>
+ array(1) {
+ [0]=>
+ string(3) "123"
+ }
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_success_multi_level_map.phpt b/ext/uri/tests/query_params/from_array_success_multi_level_map.phpt
new file mode 100644
index 000000000000..e4a9a0c468db
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_multi_level_map.phpt
@@ -0,0 +1,70 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - nested maps preserve explicit indices
+--FILE--
+ ["bar" => [0 => "baz", 2 => 123, 3 => [], 4 => [1, 2, 3]]]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(5) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(11) "foo[bar][0]"
+ [1]=>
+ string(3) "baz"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(11) "foo[bar][2]"
+ [1]=>
+ string(3) "123"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(13) "foo[bar][4][]"
+ [1]=>
+ string(1) "1"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(13) "foo[bar][4][]"
+ [1]=>
+ string(1) "2"
+ }
+ [4]=>
+ array(2) {
+ [0]=>
+ string(13) "foo[bar][4][]"
+ [1]=>
+ string(1) "3"
+ }
+}
+array(1) {
+ ["foo"]=>
+ array(1) {
+ ["bar"]=>
+ array(3) {
+ [0]=>
+ string(3) "baz"
+ [2]=>
+ string(3) "123"
+ [4]=>
+ array(3) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+ [2]=>
+ string(1) "3"
+ }
+ }
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_success_numeric_keys.phpt b/ext/uri/tests/query_params/from_array_success_numeric_keys.phpt
new file mode 100644
index 000000000000..f484819eeb61
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_numeric_keys.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - root integer keys become parameter names
+--FILE--
+ "two", "01" => "leading", -1 => "negative", 0 => "zero"]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(3) "two"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(2) "01"
+ [1]=>
+ string(7) "leading"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(2) "-1"
+ [1]=>
+ string(8) "negative"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(1) "0"
+ [1]=>
+ string(4) "zero"
+ }
+}
+array(4) {
+ [2]=>
+ string(3) "two"
+ ["01"]=>
+ string(7) "leading"
+ [-1]=>
+ string(8) "negative"
+ [0]=>
+ string(4) "zero"
+}
diff --git a/ext/uri/tests/query_params/from_array_success_omitted_indices.phpt b/ext/uri/tests/query_params/from_array_success_omitted_indices.phpt
new file mode 100644
index 000000000000..657a1aa47954
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_omitted_indices.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - omitted list elements leave gaps when indices are explicit
+--FILE--
+ ["one", [], "two"]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "k[0]"
+ [1]=>
+ string(3) "one"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(4) "k[2]"
+ [1]=>
+ string(3) "two"
+ }
+}
+array(1) {
+ ["k"]=>
+ array(2) {
+ [0]=>
+ string(3) "one"
+ [2]=>
+ string(3) "two"
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_success_reference_values.phpt b/ext/uri/tests/query_params/from_array_success_reference_values.phpt
new file mode 100644
index 000000000000..a4bcedd34c39
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_reference_values.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - later changes to referenced values do not affect parameters
+--FILE--
+ &$value];
+$params1 = Uri\QueryParams::fromArray($array);
+$value = "after";
+$params2 = Uri\QueryParams::fromArray($array);
+
+var_dump($params1->getFirst("key"));
+var_dump($params2->getFirst("key"));
+
+?>
+--EXPECT--
+string(6) "before"
+string(5) "after"
diff --git a/ext/uri/tests/query_params/from_array_success_references.phpt b/ext/uri/tests/query_params/from_array_success_references.phpt
new file mode 100644
index 000000000000..11ba6032c87f
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_references.phpt
@@ -0,0 +1,66 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - shared arrays and scalar references
+--FILE--
+ &$scalar];
+$params = Uri\QueryParams::fromArray(["left" => &$shared, "right" => &$shared, "list" => [&$scalar, &$shared]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(11) "left[value]"
+ [1]=>
+ string(1) "7"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(12) "right[value]"
+ [1]=>
+ string(1) "7"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(7) "list[0]"
+ [1]=>
+ string(1) "7"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(14) "list[1][value]"
+ [1]=>
+ string(1) "7"
+ }
+}
+array(3) {
+ ["left"]=>
+ array(1) {
+ ["value"]=>
+ string(1) "7"
+ }
+ ["right"]=>
+ array(1) {
+ ["value"]=>
+ string(1) "7"
+ }
+ ["list"]=>
+ array(2) {
+ [0]=>
+ string(1) "7"
+ [1]=>
+ array(1) {
+ ["value"]=>
+ string(1) "7"
+ }
+ }
+}
diff --git a/ext/uri/tests/query_params/from_array_success_rows.phpt b/ext/uri/tests/query_params/from_array_success_rows.phpt
new file mode 100644
index 000000000000..f65ec5212f0c
--- /dev/null
+++ b/ext/uri/tests/query_params/from_array_success_rows.phpt
@@ -0,0 +1,61 @@
+--TEST--
+Test Uri\QueryParams::fromArray() - success - maps within a list retain their grouping
+--FILE--
+ [["a" => 1, "b" => 2], ["a" => 3, "b" => 4]]]);
+
+var_dump($params->toList());
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(10) "rows[0][a]"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(10) "rows[0][b]"
+ [1]=>
+ string(1) "2"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(10) "rows[1][a]"
+ [1]=>
+ string(1) "3"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(10) "rows[1][b]"
+ [1]=>
+ string(1) "4"
+ }
+}
+array(1) {
+ ["rows"]=>
+ array(2) {
+ [0]=>
+ array(2) {
+ ["a"]=>
+ string(1) "1"
+ ["b"]=>
+ string(1) "2"
+ }
+ [1]=>
+ array(2) {
+ ["a"]=>
+ string(1) "3"
+ ["b"]=>
+ string(1) "4"
+ }
+ }
+}
diff --git a/ext/uri/tests/query_params/from_list_error_float_non_finite.phpt b/ext/uri/tests/query_params/from_list_error_float_non_finite.phpt
new file mode 100644
index 000000000000..7cdf2627d2fe
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_error_float_non_finite.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromList() - error - non-finite float
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::fromList(): Argument #1 ($queryParams) contains a non-finite float for query parameter "x"
diff --git a/ext/uri/tests/query_params/from_list_error_name.phpt b/ext/uri/tests/query_params/from_list_error_name.phpt
new file mode 100644
index 000000000000..4537de5072d6
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_error_name.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromList() - error - non-string parameter name
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::fromList(): Argument #1 ($queryParams) must contain a string parameter name at index 0, int given
diff --git a/ext/uri/tests/query_params/from_list_error_non_list.phpt b/ext/uri/tests/query_params/from_list_error_non_list.phpt
new file mode 100644
index 000000000000..b26c4b9805b8
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_error_non_list.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromList() - error - outer array is not a list
+--FILE--
+ ["tag", "value"]]);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::fromList(): Argument #1 ($queryParams) must be a list of [name, value] pairs
diff --git a/ext/uri/tests/query_params/from_list_error_pair_keys.phpt b/ext/uri/tests/query_params/from_list_error_pair_keys.phpt
new file mode 100644
index 000000000000..86661966b2e6
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_error_pair_keys.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromList() - error - associative pair
+--FILE--
+ "tag", "value" => "first"]]);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::fromList(): Argument #1 ($queryParams) must contain a [name, value] pair at index 0
diff --git a/ext/uri/tests/query_params/from_list_error_pair_length.phpt b/ext/uri/tests/query_params/from_list_error_pair_length.phpt
new file mode 100644
index 000000000000..276bbe445964
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_error_pair_length.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromList() - error - missing value in a pair
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::fromList(): Argument #1 ($queryParams) must contain a [name, value] pair at index 0
diff --git a/ext/uri/tests/query_params/from_list_error_pair_type.phpt b/ext/uri/tests/query_params/from_list_error_pair_type.phpt
new file mode 100644
index 000000000000..857facc3c8ad
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_error_pair_type.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromList() - error - list element is not an array
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::fromList(): Argument #1 ($queryParams) must contain an array at index 1, string given
diff --git a/ext/uri/tests/query_params/from_list_error_value.phpt b/ext/uri/tests/query_params/from_list_error_value.phpt
new file mode 100644
index 000000000000..01aca68eb951
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_error_value.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::fromList() - error - invalid parameter value
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::fromList(): Argument #1 ($queryParams) contains an invalid value for query parameter "flag": expected BackedEnum|string|int|float|null, false given
diff --git a/ext/uri/tests/query_params/from_list_success_empty.phpt b/ext/uri/tests/query_params/from_list_success_empty.phpt
new file mode 100644
index 000000000000..aeb0cbb3283e
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_success_empty.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Test Uri\QueryParams::fromList() - success - empty input
+--FILE--
+toList());
+var_dump($params->count());
+
+?>
+--EXPECT--
+array(0) {
+}
+int(0)
diff --git a/ext/uri/tests/query_params/from_list_success_float_precision.phpt b/ext/uri/tests/query_params/from_list_success_float_precision.phpt
new file mode 100644
index 000000000000..7c9a91546b11
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_success_float_precision.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test Uri\QueryParams::fromList() - success - preserve float precision
+--INI--
+precision=3
+serialize_precision=-1
+--FILE--
+toList());
+var_dump($params->toRfc3986String());
+var_dump(floatval($params->getFirst("x")) === $value);
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(18) "1.2345678901234567"
+ }
+}
+string(20) "x=1.2345678901234567"
+bool(true)
diff --git a/ext/uri/tests/query_params/from_list_success_round_trip.phpt b/ext/uri/tests/query_params/from_list_success_round_trip.phpt
new file mode 100644
index 000000000000..3397ac153427
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_success_round_trip.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test Uri\QueryParams::fromList() - success - toList() round trip preserves order, duplicate names and raw bytes
+--FILE--
+append("tag", "first")
+ ->append("", null)
+ ->append("tag", "second")
+ ->append("", "")
+ ->append("a[]\0", "\xFF%20");
+$params2 = Uri\QueryParams::fromList($params1->toList());
+
+var_dump($params2->toList() === $params1->toList());
+var_dump($params2->getAll("tag"));
+var_dump($params2->getAll(""));
+var_dump(bin2hex($params2->getFirst("a[]\0")));
+
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ string(6) "second"
+}
+array(2) {
+ [0]=>
+ NULL
+ [1]=>
+ string(0) ""
+}
+string(8) "ff253230"
diff --git a/ext/uri/tests/query_params/from_list_success_values.phpt b/ext/uri/tests/query_params/from_list_success_values.phpt
new file mode 100644
index 000000000000..7d0aeeb6613e
--- /dev/null
+++ b/ext/uri/tests/query_params/from_list_success_values.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::fromList() - success - supported value types and references
+--FILE--
+toRfc3986String());
+
+?>
+--EXPECT--
+string(39) "code=200&mode=fast&number=42&ratio=1.25"
diff --git a/ext/uri/tests/query_params/get_all_success_basic.phpt b/ext/uri/tests/query_params/get_all_success_basic.phpt
new file mode 100644
index 000000000000..555acee687c1
--- /dev/null
+++ b/ext/uri/tests/query_params/get_all_success_basic.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test Uri\QueryParams::getAll() - success - strings, null and empty values in encounter order
+--FILE--
+getAll("x");
+unset($params);
+
+var_dump($values);
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ NULL
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(4) "last"
+}
diff --git a/ext/uri/tests/query_params/get_all_success_deleted_entries.phpt b/ext/uri/tests/query_params/get_all_success_deleted_entries.phpt
new file mode 100644
index 000000000000..fa4e7d8c295c
--- /dev/null
+++ b/ext/uri/tests/query_params/get_all_success_deleted_entries.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test Uri\QueryParams::getAll() - success - deleted entries and independent returned arrays
+--FILE--
+deleteValue("x", "1");
+$values = $params2->getAll("x");
+$values[0] = "changed";
+
+var_dump($params1->getAll("x"));
+var_dump($params2->getAll("x"));
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+ [2]=>
+ string(1) "1"
+ [3]=>
+ string(1) "3"
+}
+array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(1) "3"
+}
diff --git a/ext/uri/tests/query_params/get_all_success_missing_key.phpt b/ext/uri/tests/query_params/get_all_success_missing_key.phpt
new file mode 100644
index 000000000000..307b861914f2
--- /dev/null
+++ b/ext/uri/tests/query_params/get_all_success_missing_key.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::getAll() - success - parameter names are matched literally
+--FILE--
+getAll("x"));
+var_dump($params->getAll("x[]"));
+
+?>
+--EXPECT--
+array(0) {
+}
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+}
diff --git a/ext/uri/tests/query_params/get_iterator_basic.phpt b/ext/uri/tests/query_params/get_iterator_basic.phpt
new file mode 100644
index 000000000000..b5f0456c4f84
--- /dev/null
+++ b/ext/uri/tests/query_params/get_iterator_basic.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test Uri\QueryParams::getIterator() - success - basic
+--FILE--
+
+--EXPECT--
+array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "123"
+}
+array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "456"
+}
+array(2) {
+ [0]=>
+ string(3) "bar"
+ [1]=>
+ string(3) "789"
+}
diff --git a/ext/uri/tests/query_params/get_iterator_success_immutable.phpt b/ext/uri/tests/query_params/get_iterator_success_immutable.phpt
new file mode 100644
index 000000000000..3a81dcae335f
--- /dev/null
+++ b/ext/uri/tests/query_params/get_iterator_success_immutable.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::getIterator() - success - an iterator retains the original parameters
+--FILE--
+getIterator();
+ return $params;
+}
+
+$params = createParams($iterator)->set("x", "3");
+
+var_dump(iterator_to_array($iterator) === [["x", "1"], ["x", "2"]]);
+var_dump($params->toRfc3986String());
+
+?>
+--EXPECT--
+bool(true)
+string(3) "x=3"
diff --git a/ext/uri/tests/query_params/get_iterator_success_tombstones.phpt b/ext/uri/tests/query_params/get_iterator_success_tombstones.phpt
new file mode 100644
index 000000000000..a153bf4b8454
--- /dev/null
+++ b/ext/uri/tests/query_params/get_iterator_success_tombstones.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Test Uri\QueryParams::getIterator() - consecutive keys after deleting entries
+--FILE--
+append("x", "0")->append("y", "first")
+ ->append("x", "1")->append("y", "second")
+ ->append("x", "2")->append("z", "last")->append("x", "3")
+ ->delete("x");
+
+var_dump(iterator_to_array($params) === $params->toList());
+
+$iterator = $params->getIterator();
+var_dump($iterator->key(), $iterator->current());
+$iterator->next();
+$iterator->next();
+var_dump($iterator->key(), $iterator->current());
+$iterator->next();
+var_dump($iterator->valid());
+$iterator->rewind();
+var_dump($iterator->key(), $iterator->current());
+
+?>
+--EXPECT--
+bool(true)
+int(0)
+array(2) {
+ [0]=>
+ string(1) "y"
+ [1]=>
+ string(5) "first"
+}
+int(2)
+array(2) {
+ [0]=>
+ string(1) "z"
+ [1]=>
+ string(4) "last"
+}
+bool(false)
+int(0)
+array(2) {
+ [0]=>
+ string(1) "y"
+ [1]=>
+ string(5) "first"
+}
diff --git a/ext/uri/tests/query_params/has_success_existing.phpt b/ext/uri/tests/query_params/has_success_existing.phpt
new file mode 100644
index 000000000000..d419158fe23b
--- /dev/null
+++ b/ext/uri/tests/query_params/has_success_existing.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\QueryParams::has() - success - existing
+--FILE--
+has("abc"));
+
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/uri/tests/query_params/has_success_non_existent.phpt b/ext/uri/tests/query_params/has_success_non_existent.phpt
new file mode 100644
index 000000000000..d3d2a3f866f1
--- /dev/null
+++ b/ext/uri/tests/query_params/has_success_non_existent.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\QueryParams::has() - success - non-existent
+--FILE--
+has("bar"));
+
+?>
+--EXPECT--
+bool(false)
diff --git a/ext/uri/tests/query_params/has_value_error_bool.phpt b/ext/uri/tests/query_params/has_value_error_bool.phpt
new file mode 100644
index 000000000000..ac5208589291
--- /dev/null
+++ b/ext/uri/tests/query_params/has_value_error_bool.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::hasValue() - error - boolean value with strict types
+--FILE--
+hasValue("x", true);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::hasValue(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, true given
diff --git a/ext/uri/tests/query_params/has_value_error_float_non_finite.phpt b/ext/uri/tests/query_params/has_value_error_float_non_finite.phpt
new file mode 100644
index 000000000000..4ed400c1ec56
--- /dev/null
+++ b/ext/uri/tests/query_params/has_value_error_float_non_finite.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::hasValue() - error - non-finite float
+--FILE--
+append("x", "NAN");
+
+try {
+ $result = $params->hasValue("x", NAN);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params->hasValue("x", "NAN"));
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::hasValue(): Argument #2 ($value) must be finite
+bool(true)
diff --git a/ext/uri/tests/query_params/has_value_success_existing_key_missing_value.phpt b/ext/uri/tests/query_params/has_value_success_existing_key_missing_value.phpt
new file mode 100644
index 000000000000..8515b9a34e15
--- /dev/null
+++ b/ext/uri/tests/query_params/has_value_success_existing_key_missing_value.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\QueryParams::hasValue() - success - existing key, missing value
+--FILE--
+hasValue("foo", 123));
+
+?>
+--EXPECT--
+bool(false)
diff --git a/ext/uri/tests/query_params/has_value_success_existing_key_value.phpt b/ext/uri/tests/query_params/has_value_success_existing_key_value.phpt
new file mode 100644
index 000000000000..a5e4a53d43d5
--- /dev/null
+++ b/ext/uri/tests/query_params/has_value_success_existing_key_value.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\QueryParams::hasValue() - success - existing key, existing value
+--FILE--
+hasValue("foo", "bar"));
+
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/uri/tests/query_params/has_value_success_int.phpt b/ext/uri/tests/query_params/has_value_success_int.phpt
new file mode 100644
index 000000000000..260ac3c1c118
--- /dev/null
+++ b/ext/uri/tests/query_params/has_value_success_int.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\QueryParams::hasValue() - success - int value
+--FILE--
+hasValue("abc", "123"));
+
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/uri/tests/query_params/has_value_success_missing_key.phpt b/ext/uri/tests/query_params/has_value_success_missing_key.phpt
new file mode 100644
index 000000000000..89627230ea88
--- /dev/null
+++ b/ext/uri/tests/query_params/has_value_success_missing_key.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\QueryParams::hasValue() - success - missing key
+--FILE--
+hasValue("baz", "abc"));
+
+?>
+--EXPECT--
+bool(false)
diff --git a/ext/uri/tests/query_params/has_value_success_weak_types.phpt b/ext/uri/tests/query_params/has_value_success_weak_types.phpt
new file mode 100644
index 000000000000..365ba66cc03f
--- /dev/null
+++ b/ext/uri/tests/query_params/has_value_success_weak_types.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Test Uri\QueryParams::hasValue() - success - weak boolean and Stringable conversion
+--FILE--
+hasValue("a", false));
+var_dump($params->hasValue("a", true));
+var_dump($params->hasValue("b", new Value()));
+var_dump($params->hasValue("c", false));
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(false)
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_additional_equals.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_additional_equals.phpt
new file mode 100644
index 000000000000..887e1268fddf
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_additional_equals.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - only the first equals sign separates the name and value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "a=b"
+ }
+}
+string(9) "foo=a%3Db"
+string(9) "foo=a%3Db"
+string(9) "foo=a%3Db"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_asterisk.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_asterisk.phpt
new file mode 100644
index 000000000000..4b2d818cd9e8
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_asterisk.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an unencoded asterisk
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "a*b"
+ }
+}
+string(9) "foo=a%2Ab"
+string(7) "foo=a*b"
+string(7) "foo=a*b"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_basic.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_basic.phpt
new file mode 100644
index 000000000000..d4fd7f93eb97
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - basic
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(15) "abc=123&foo=bar"
+string(15) "abc=123&foo=bar"
+string(15) "abc=123&foo=bar"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_brackets.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_brackets.phpt
new file mode 100644
index 000000000000..27858a201760
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_brackets.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - unencoded brackets
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a[]"
+ [1]=>
+ string(1) "1"
+ }
+}
+string(9) "a%5B%5D=1"
+string(9) "a%5B%5D=1"
+string(9) "a%5B%5D=1"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_empty.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_empty.phpt
new file mode 100644
index 000000000000..6f1a82c43188
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_empty.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - empty string
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_empty_edge_fields.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_empty_edge_fields.phpt
new file mode 100644
index 000000000000..dcfe23b4ad84
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_empty_edge_fields.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - leading and trailing empty fields
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+}
+string(9) "&foo=bar&"
+string(9) "&foo=bar&"
+string(7) "foo=bar"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_empty_pair.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_empty_pair.phpt
new file mode 100644
index 000000000000..9d39b6a9c90c
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_empty_pair.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an empty field between parameters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(1) "1"
+ }
+}
+string(8) "a=1&&b=1"
+string(8) "a=1&&b=1"
+string(7) "a=1&b=1"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_encoded_asterisk.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_asterisk.phpt
new file mode 100644
index 000000000000..37b2e342f146
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_asterisk.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - a percent-encoded asterisk
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "a*b"
+ }
+}
+string(9) "foo=a%2Ab"
+string(7) "foo=a*b"
+string(7) "foo=a*b"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_encoded_delimiters.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_delimiters.phpt
new file mode 100644
index 000000000000..eca387dd1b9a
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_delimiters.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - percent-encoded parameter delimiters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "&a=b&"
+ [1]=>
+ string(5) "=c&d="
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(3) "%26"
+ }
+}
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_encoded_leading_question_mark.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_leading_question_mark.phpt
new file mode 100644
index 000000000000..f1cc4e009973
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_leading_question_mark.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - a percent-encoded leading question mark is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "?foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(10) "%3Ffoo=bar"
+string(8) "?foo=bar"
+string(10) "%3Ffoo=bar"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_encoded_plus.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_plus.phpt
new file mode 100644
index 000000000000..691b329d9023
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_encoded_plus.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - percent-encoded plus signs remain literal
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a+b"
+ [1]=>
+ string(5) "c+d e"
+ }
+}
+string(13) "a%2Bb=c%2Bd+e"
+string(11) "a+b=c+d%20e"
+string(13) "a%2Bb=c%2Bd+e"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_fragment.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_fragment.phpt
new file mode 100644
index 000000000000..d4099aefe23f
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_fragment.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an unencoded fragment delimiter is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(2) "ok"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(6) "#value"
+ }
+}
+string(15) "ok=1&a=%23value"
+string(15) "ok=1&a=%23value"
+string(15) "ok=1&a=%23value"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_leading_question_mark.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_leading_question_mark.phpt
new file mode 100644
index 000000000000..d3d2b9ac75d1
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_leading_question_mark.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - a leading question mark is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "?foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(10) "%3Ffoo=bar"
+string(8) "?foo=bar"
+string(10) "%3Ffoo=bar"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte.phpt
new file mode 100644
index 000000000000..ed4d5e679ee5
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an unencoded NUL byte
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(3) "x%0y"
+ }
+}
+string(7) "a=x%r\x25%r00y"
+string(7) "a=x%r\x25%r00y"
+string(7) "a=x%r\x25%r00y"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_percent_encoding.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_percent_encoding.phpt
new file mode 100644
index 000000000000..006a173d611b
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_percent_encoding.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - NUL bytes before and after percent-decoding
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a%0b"
+ [1]=>
+ string(3) "c%0d"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(2) "%0x"
+ [1]=>
+ string(2) "y%0"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(4) "next"
+ [1]=>
+ string(2) "ok"
+ }
+}
+string(29) "a%r\x25%r00b=c%r\x25%r00d&%r\x25%r00x=y%r\x25%r00&next=ok"
+string(29) "a%r\x25%r00b=c%r\x25%r00d&%r\x25%r00x=y%r\x25%r00&next=ok"
+string(29) "a%r\x25%r00b=c%r\x25%r00d&%r\x25%r00x=y%r\x25%r00&next=ok"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_percent_encoding_malformed.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_percent_encoding_malformed.phpt
new file mode 100644
index 000000000000..64ecad719d7a
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_percent_encoding_malformed.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - NUL bytes next to malformed percent escapes
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(4) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a%0%r\x25%r"
+ [1]=>
+ string(4) "b%0%r\x25%r2"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "c"
+ [1]=>
+ string(2) "%r\x25%r%0"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(1) "d"
+ [1]=>
+ string(3) "%r\x25%r2%0"
+ }
+ [3]=>
+ array(2) {
+ [0]=>
+ string(4) "next"
+ [1]=>
+ string(2) "ok"
+ }
+}
+string(43) "a%r\x25%r00%r\x25%r25=b%r\x25%r00%r\x25%r252&c=%r\x25%r25%r\x25%r00&d=%r\x25%r252%r\x25%r00&next=ok"
+string(43) "a%r\x25%r00%r\x25%r25=b%r\x25%r00%r\x25%r252&c=%r\x25%r25%r\x25%r00&d=%r\x25%r252%r\x25%r00&next=ok"
+string(43) "a%r\x25%r00%r\x25%r25=b%r\x25%r00%r\x25%r252&c=%r\x25%r25%r\x25%r00&d=%r\x25%r252%r\x25%r00&next=ok"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_plus.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_plus.phpt
new file mode 100644
index 000000000000..ed3a56021878
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_nul_byte_plus.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - NUL bytes before and after plus-to-space conversion
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "a %0b"
+ [1]=>
+ string(4) "c%0 d"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(4) "next"
+ [1]=>
+ string(2) "ok"
+ }
+}
+string(21) "a+%r\x25%r00b=c%r\x25%r00+d&next=ok"
+string(25) "a%r\x25%r20%r\x25%r00b=c%r\x25%r00%r\x25%r20d&next=ok"
+string(21) "a+%r\x25%r00b=c%r\x25%r00+d&next=ok"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_null.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_null.phpt
new file mode 100644
index 000000000000..d048b4d2e667
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_null.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - null value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(1) "c"
+ }
+}
+string(5) "a&b=c"
+string(5) "a&b=c"
+string(5) "a&b=c"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_only_empty_fields.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_only_empty_fields.phpt
new file mode 100644
index 000000000000..ecedca504203
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_only_empty_fields.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - a query consisting of empty fields
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+}
+string(1) "&"
+string(1) "&"
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_incomplete.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_incomplete.phpt
new file mode 100644
index 000000000000..f79357c5d729
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_incomplete.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an incomplete percent escape is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "%"
+ }
+}
+string(5) "a=%25"
+string(5) "a=%25"
+string(5) "a=%25"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_invalid.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_invalid.phpt
new file mode 100644
index 000000000000..b14edd4d3871
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_invalid.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an invalid percent escape in a parameter value is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(3) "%0G"
+ }
+}
+string(7) "a=%250G"
+string(7) "a=%250G"
+string(7) "a=%250G"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_invalid_name.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_invalid_name.phpt
new file mode 100644
index 000000000000..bb29b5c47236
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_invalid_name.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an invalid percent escape in a parameter name is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(2) "ok"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "%G0"
+ [1]=>
+ string(5) "value"
+ }
+}
+string(16) "ok=1&%25G0=value"
+string(16) "ok=1&%25G0=value"
+string(16) "ok=1&%25G0=value"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_truncated.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_truncated.phpt
new file mode 100644
index 000000000000..0e288f73e3da
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_percent_encoding_truncated.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - a percent escape with only one hexadecimal digit is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(2) "%2"
+ }
+}
+string(6) "a=%252"
+string(6) "a=%252"
+string(6) "a=%252"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_plus.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_plus.phpt
new file mode 100644
index 000000000000..95c1ae6e73f9
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_plus.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - plus signs without percent-encoded bytes
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a b"
+ [1]=>
+ string(3) "c d"
+ }
+}
+string(7) "a+b=c+d"
+string(11) "a%20b=c%20d"
+string(7) "a+b=c+d"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_reserved.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_reserved.phpt
new file mode 100644
index 000000000000..db1266d9e63f
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_reserved.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - percent-encoded reserved characters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "ab:c"
+ [1]=>
+ string(4) "#123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(5) ""
+ [1]=>
+ string(5) "b@r/?"
+ }
+}
+string(35) "ab%3Ac=%23123&%3Cfoo%3E=b%40r%2F%3F"
+string(27) "ab:c=%23123&%3Cfoo%3E=b@r/?"
+string(35) "ab%3Ac=%23123&%3Cfoo%3E=b%40r%2F%3F"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_reserved_name.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_reserved_name.phpt
new file mode 100644
index 000000000000..a5814db19a79
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_reserved_name.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an unencoded reserved character in a parameter name
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(7) "foo:bar"
+ [1]=>
+ string(5) "value"
+ }
+}
+string(15) "foo%3Abar=value"
+string(13) "foo:bar=value"
+string(15) "foo%3Abar=value"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_reserved_value.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_reserved_value.phpt
new file mode 100644
index 000000000000..63e3176302d8
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_reserved_value.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an unencoded reserved character in a parameter value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "a/b"
+ }
+}
+string(9) "foo=a%2Fb"
+string(7) "foo=a/b"
+string(9) "foo=a%2Fb"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_semicolon.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_semicolon.phpt
new file mode 100644
index 000000000000..e7bbec2b8110
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_semicolon.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an unencoded semicolon is not a parameter separator
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(5) "1;b=2"
+ }
+}
+string(11) "a=1%3Bb%3D2"
+string(9) "a=1;b%3D2"
+string(11) "a=1%3Bb%3D2"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_space.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_space.phpt
new file mode 100644
index 000000000000..81eef1de78ef
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_space.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - an unencoded space
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(7) "foo bar"
+ }
+}
+string(9) "a=foo+bar"
+string(11) "a=foo%20bar"
+string(9) "a=foo+bar"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_unreserved.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_unreserved.phpt
new file mode 100644
index 000000000000..2c54ffcb1f5d
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_unreserved.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - unreserved characters remain literal
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(10) "AZaz09-._~"
+ [1]=>
+ string(10) "AZaz09-._~"
+ }
+}
+string(21) "AZaz09-._~=AZaz09-._~"
+string(21) "AZaz09-._~=AZaz09-._~"
+string(25) "AZaz09-._%7E=AZaz09-._%7E"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_utf8_incomplete.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_incomplete.phpt
new file mode 100644
index 000000000000..503bd40504b9
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_incomplete.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - incomplete percent-encoded UTF-8
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "%r\x61\xE2\x82%r"
+ [1]=>
+ string(3) "%r\x62\xE2\x82%r"
+ }
+}
+string(15) "a%E2%82=b%E2%82"
+string(15) "a%E2%82=b%E2%82"
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_utf8_invalid.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_invalid.phpt
new file mode 100644
index 000000000000..4d7a372c167d
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_invalid.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - invalid percent-encoded UTF-8
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "%r\x61\xFF\x7A%r"
+ [1]=>
+ string(3) "%r\x62\xFF\x79%r"
+ }
+}
+string(11) "a%FFz=b%FFy"
+string(11) "a%FFz=b%FFy"
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_utf8_invalid_raw.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_invalid_raw.phpt
new file mode 100644
index 000000000000..9eb745e685f0
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_invalid_raw.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - unencoded invalid UTF-8 is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "%r\xFF%r"
+ }
+}
+string(5) "a=%FF"
+string(5) "a=%FF"
+string(11) "a=%EF%BF%BD"
diff --git a/ext/uri/tests/query_params/parse_rfc1866_success_utf8_valid_raw.phpt b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_valid_raw.phpt
new file mode 100644
index 000000000000..9fc4810de91b
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc1866_success_utf8_valid_raw.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc1866() - success - unencoded valid UTF-8
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(2) "é"
+ }
+}
+string(8) "a=%C3%A9"
+string(8) "a=%C3%A9"
+string(8) "a=%C3%A9"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_brackets.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_brackets.phpt
new file mode 100644
index 000000000000..54f1871d1938
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_brackets.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - unencoded brackets
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_fragment.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_fragment.phpt
new file mode 100644
index 000000000000..92d464654979
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_fragment.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - an unencoded fragment delimiter
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_negative_param_count.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_negative_param_count.phpt
new file mode 100644
index 000000000000..51c2ff347256
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_negative_param_count.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - negative param count
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::parseRfc3986(): Argument #2 ($maxParamCount) must be greater than or equal to 0
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_nul_byte.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_nul_byte.phpt
new file mode 100644
index 000000000000..e25cecc1d628
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_nul_byte.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - an unencoded NUL byte
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_param_count.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_param_count.phpt
new file mode 100644
index 000000000000..6dbd61d60409
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_param_count.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - param count exceeds the limit
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string contains too many parameters
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_incomplete.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_incomplete.phpt
new file mode 100644
index 000000000000..d60f0a2a431c
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_incomplete.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - an incomplete percent escape
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_invalid.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_invalid.phpt
new file mode 100644
index 000000000000..bab329eef33e
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_invalid.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - an invalid hexadecimal digit in a parameter value
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_invalid_name.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_invalid_name.phpt
new file mode 100644
index 000000000000..190ef18233a9
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_invalid_name.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - an invalid percent escape in a parameter name
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_truncated.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_truncated.phpt
new file mode 100644
index 000000000000..5235db92726d
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_percent_encoding_truncated.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - a percent escape with only one hexadecimal digit
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_space.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_space.phpt
new file mode 100644
index 000000000000..168b561ba551
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_space.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - an unencoded space
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_utf8_invalid_raw.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_utf8_invalid_raw.phpt
new file mode 100644
index 000000000000..e737965dffef
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_utf8_invalid_raw.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - unencoded invalid UTF-8
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_error_utf8_valid_raw.phpt b/ext/uri/tests/query_params/parse_rfc3986_error_utf8_valid_raw.phpt
new file mode 100644
index 000000000000..4047e30a3cde
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_error_utf8_valid_raw.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - error - unencoded valid UTF-8
+--FILE--
+getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The specified query string is malformed
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_basic.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_basic.phpt
new file mode 100644
index 000000000000..025aaad89d52
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - basic
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(15) "abc=123&foo=bar"
+string(15) "abc=123&foo=bar"
+string(15) "abc=123&foo=bar"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_empty.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_empty.phpt
new file mode 100644
index 000000000000..7d6e9a653f7b
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_empty.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - empty string
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_empty_edge_fields.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_empty_edge_fields.phpt
new file mode 100644
index 000000000000..667a59c3307d
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_empty_edge_fields.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - leading and trailing empty fields
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+}
+string(9) "&foo=bar&"
+string(9) "&foo=bar&"
+string(7) "foo=bar"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_empty_key.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_empty_key.phpt
new file mode 100644
index 000000000000..c89cb442f0a0
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_empty_key.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - empty query param pair
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(1) "2"
+ }
+}
+string(5) "=1&=2"
+string(5) "=1&=2"
+string(5) "=1&=2"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_empty_pair.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_empty_pair.phpt
new file mode 100644
index 000000000000..c77c3e57b620
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_empty_pair.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - empty query param pair
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(1) "1"
+ }
+}
+string(8) "a=1&&b=1"
+string(8) "a=1&&b=1"
+string(7) "a=1&b=1"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_empty_value.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_empty_value.phpt
new file mode 100644
index 000000000000..52d96d611c49
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_empty_value.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - empty query param pair
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(0) ""
+ }
+}
+string(2) "a="
+string(2) "a="
+string(2) "a="
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_encoded_delimiters.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_encoded_delimiters.phpt
new file mode 100644
index 000000000000..6622fafaa4b2
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_encoded_delimiters.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - percent-encoded parameter delimiters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "&a=b&"
+ [1]=>
+ string(5) "=c&d="
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(3) "%26"
+ }
+}
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_leading_question_mark.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_leading_question_mark.phpt
new file mode 100644
index 000000000000..8948a182fd13
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_leading_question_mark.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - a leading question mark is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "?foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(10) "%3Ffoo=bar"
+string(8) "?foo=bar"
+string(10) "%3Ffoo=bar"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_long_query_string.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_long_query_string.phpt
new file mode 100644
index 000000000000..871a208d9678
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_long_query_string.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - long query string
+--FILE--
+toList() === [["x", $value]]);
+var_dump($params->toRfc1866String() === $query);
+var_dump($params->toRfc3986String() === $query);
+var_dump($params->toWhatWgUrlString() === $query);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_null.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_null.phpt
new file mode 100644
index 000000000000..8cc2d03abf36
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_null.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - null value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(1) "c"
+ }
+}
+string(5) "a&b=c"
+string(5) "a&b=c"
+string(5) "a&b=c"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_only_empty_fields.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_only_empty_fields.phpt
new file mode 100644
index 000000000000..df90cd5c2628
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_only_empty_fields.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - a query consisting of empty fields
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ NULL
+ }
+}
+string(1) "&"
+string(1) "&"
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_param_count.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_param_count.phpt
new file mode 100644
index 000000000000..4d2aedc473c8
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_param_count.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - param count equals the limit
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "2"
+ }
+}
+string(7) "a=1&a=2"
+string(7) "a=1&a=2"
+string(7) "a=1&a=2"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_plus.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_plus.phpt
new file mode 100644
index 000000000000..8411d14a943e
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_plus.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - plus signs without percent-encoded bytes
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a+b"
+ [1]=>
+ string(3) "c+d"
+ }
+}
+string(11) "a%2Bb=c%2Bd"
+string(7) "a+b=c+d"
+string(11) "a%2Bb=c%2Bd"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_reserved.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_reserved.phpt
new file mode 100644
index 000000000000..fc42fa947648
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_reserved.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - reserved and percent-encoded characters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "ab:c"
+ [1]=>
+ string(4) "#123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(5) ""
+ [1]=>
+ string(5) "b@r/?"
+ }
+}
+string(35) "ab%3Ac=%23123&%3Cfoo%3E=b%40r%2F%3F"
+string(27) "ab:c=%23123&%3Cfoo%3E=b@r/?"
+string(35) "ab%3Ac=%23123&%3Cfoo%3E=b%40r%2F%3F"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_space.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_space.phpt
new file mode 100644
index 000000000000..2a723416441c
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_space.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - percent-encoded space characters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a c"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "b r"
+ }
+}
+string(15) "a+c=123&foo=b+r"
+string(19) "a%20c=123&foo=b%20r"
+string(15) "a+c=123&foo=b+r"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_utf8_incomplete.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_utf8_incomplete.phpt
new file mode 100644
index 000000000000..1fab92f36222
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_utf8_incomplete.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - incomplete percent-encoded UTF-8
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "%r\x61\xE2\x82%r"
+ [1]=>
+ string(3) "%r\x62\xE2\x82%r"
+ }
+}
+string(15) "a%E2%82=b%E2%82"
+string(15) "a%E2%82=b%E2%82"
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_utf8_invalid.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_utf8_invalid.phpt
new file mode 100644
index 000000000000..61fa3e9eb8d6
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_utf8_invalid.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - invalid percent-encoded UTF-8
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "%r\x61\xFF\x7A%r"
+ [1]=>
+ string(3) "%r\x62\xFF\x79%r"
+ }
+}
+string(11) "a%FFz=b%FFy"
+string(11) "a%FFz=b%FFy"
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
diff --git a/ext/uri/tests/query_params/parse_rfc3986_success_zero_param_count.phpt b/ext/uri/tests/query_params/parse_rfc3986_success_zero_param_count.phpt
new file mode 100644
index 000000000000..0f0e8c8c4a39
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_rfc3986_success_zero_param_count.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::parseRfc3986() - success - zero param count disables the limit
+--FILE--
+toList() === array_fill(0, 2000, ["x", "1"]));
+var_dump($params->toRfc1866String() === $query);
+var_dump($params->toRfc3986String() === $query);
+var_dump($params->toWhatWgUrlString() === $query);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_additional_equals.phpt b/ext/uri/tests/query_params/parse_whatwg_success_additional_equals.phpt
new file mode 100644
index 000000000000..0ee0624ecdae
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_additional_equals.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - only the first equals sign separates the name and value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "a=b"
+ }
+}
+string(9) "foo=a%3Db"
+string(9) "foo=a%3Db"
+string(9) "foo=a%3Db"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_basic.phpt b/ext/uri/tests/query_params/parse_whatwg_success_basic.phpt
new file mode 100644
index 000000000000..e18c9f4f3298
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - basic
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "abc"
+ [1]=>
+ string(3) "123"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(15) "abc=123&foo=bar"
+string(15) "abc=123&foo=bar"
+string(15) "abc=123&foo=bar"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_empty.phpt b/ext/uri/tests/query_params/parse_whatwg_success_empty.phpt
new file mode 100644
index 000000000000..08c3c7b45cab
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_empty.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - empty string
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_empty_edge_fields.phpt b/ext/uri/tests/query_params/parse_whatwg_success_empty_edge_fields.phpt
new file mode 100644
index 000000000000..9fb51daf8a77
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_empty_edge_fields.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - leading and trailing empty fields
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(7) "foo=bar"
+string(7) "foo=bar"
+string(7) "foo=bar"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_empty_name.phpt b/ext/uri/tests/query_params/parse_whatwg_success_empty_name.phpt
new file mode 100644
index 000000000000..3b07fa64c32e
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_empty_name.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - an empty name with a value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(4) "=bar"
+string(4) "=bar"
+string(4) "=bar"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_empty_name_and_value.phpt b/ext/uri/tests/query_params/parse_whatwg_success_empty_name_and_value.phpt
new file mode 100644
index 000000000000..3c042e407488
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_empty_name_and_value.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - an empty name and value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(0) ""
+ }
+}
+string(1) "="
+string(1) "="
+string(1) "="
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_empty_pair.phpt b/ext/uri/tests/query_params/parse_whatwg_success_empty_pair.phpt
new file mode 100644
index 000000000000..7b20224250c4
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_empty_pair.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - an empty field between parameters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(1) "1"
+ }
+}
+string(7) "a=1&b=1"
+string(7) "a=1&b=1"
+string(7) "a=1&b=1"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_empty_value.phpt b/ext/uri/tests/query_params/parse_whatwg_success_empty_value.phpt
new file mode 100644
index 000000000000..f76166aefe6e
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_empty_value.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - an empty value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(0) ""
+ }
+}
+string(4) "foo="
+string(4) "foo="
+string(4) "foo="
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_encoded_delimiters.phpt b/ext/uri/tests/query_params/parse_whatwg_success_encoded_delimiters.phpt
new file mode 100644
index 000000000000..06f1a8ba3664
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_encoded_delimiters.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - percent-encoded parameter delimiters
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "&a=b&"
+ [1]=>
+ string(5) "=c&d="
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(3) "%26"
+ }
+}
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
+string(31) "%26a%3Db%26=%3Dc%26d%3D&x=%2526"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_encoded_leading_question_mark.phpt b/ext/uri/tests/query_params/parse_whatwg_success_encoded_leading_question_mark.phpt
new file mode 100644
index 000000000000..12a769b178d7
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_encoded_leading_question_mark.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a percent-encoded leading question mark is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "?foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(10) "%3Ffoo=bar"
+string(8) "?foo=bar"
+string(10) "%3Ffoo=bar"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_leading_question_mark.phpt b/ext/uri/tests/query_params/parse_whatwg_success_leading_question_mark.phpt
new file mode 100644
index 000000000000..05adc18d8540
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_leading_question_mark.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a leading question mark is removed
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(7) "foo=bar"
+string(7) "foo=bar"
+string(7) "foo=bar"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_leading_question_mark_missing_value.phpt b/ext/uri/tests/query_params/parse_whatwg_success_leading_question_mark_missing_value.phpt
new file mode 100644
index 000000000000..3ad478002b1f
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_leading_question_mark_missing_value.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a leading question mark followed by a name without a value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(0) ""
+ }
+}
+string(4) "foo="
+string(4) "foo="
+string(4) "foo="
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_missing_value.phpt b/ext/uri/tests/query_params/parse_whatwg_success_missing_value.phpt
new file mode 100644
index 000000000000..d54c2b786401
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_missing_value.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - missing value becomes an empty string
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(0) ""
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(1) "c"
+ }
+}
+string(6) "a=&b=c"
+string(6) "a=&b=c"
+string(6) "a=&b=c"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_missing_value_only.phpt b/ext/uri/tests/query_params/parse_whatwg_success_missing_value_only.phpt
new file mode 100644
index 000000000000..fd662fad0afa
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_missing_value_only.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a name without a value
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(0) ""
+ }
+}
+string(4) "foo="
+string(4) "foo="
+string(4) "foo="
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_multiple_empty_fields.phpt b/ext/uri/tests/query_params/parse_whatwg_success_multiple_empty_fields.phpt
new file mode 100644
index 000000000000..91707a135502
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_multiple_empty_fields.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - multiple empty fields
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_multiple_leading_question_marks.phpt b/ext/uri/tests/query_params/parse_whatwg_success_multiple_leading_question_marks.phpt
new file mode 100644
index 000000000000..4e291d7cfe60
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_multiple_leading_question_marks.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - only the first leading question mark is removed
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "?foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(10) "%3Ffoo=bar"
+string(8) "?foo=bar"
+string(10) "%3Ffoo=bar"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_only_empty_fields.phpt b/ext/uri/tests/query_params/parse_whatwg_success_only_empty_fields.phpt
new file mode 100644
index 000000000000..5eb8fcbf5258
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_only_empty_fields.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a query consisting of empty fields
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_percent_encoding_malformed.phpt b/ext/uri/tests/query_params/parse_whatwg_success_percent_encoding_malformed.phpt
new file mode 100644
index 000000000000..5e24a143fd7d
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_percent_encoding_malformed.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - malformed percent escapes remain literal
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "%"
+ [1]=>
+ string(1) "x"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(2) "%2"
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ string(3) "bar"
+ [1]=>
+ string(3) "%GG"
+ }
+}
+string(24) "%25=x&foo=%252&bar=%25GG"
+string(24) "%25=x&foo=%252&bar=%25GG"
+string(24) "%25=x&foo=%252&bar=%25GG"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_plus.phpt b/ext/uri/tests/query_params/parse_whatwg_success_plus.phpt
new file mode 100644
index 000000000000..a9ed2bcdb7d6
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_plus.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - plus signs without percent-encoded bytes
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "a b"
+ [1]=>
+ string(3) "c d"
+ }
+}
+string(7) "a+b=c+d"
+string(11) "a%20b=c%20d"
+string(7) "a+b=c+d"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_question_mark_only.phpt b/ext/uri/tests/query_params/parse_whatwg_success_question_mark_only.phpt
new file mode 100644
index 000000000000..46b37b621d37
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_question_mark_only.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a lone question mark produces an empty list
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_trailing_empty_field.phpt b/ext/uri/tests/query_params/parse_whatwg_success_trailing_empty_field.phpt
new file mode 100644
index 000000000000..710ae89216d5
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_trailing_empty_field.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a trailing empty field is skipped
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(7) "foo=bar"
+string(7) "foo=bar"
+string(7) "foo=bar"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_trailing_empty_name_and_value.phpt b/ext/uri/tests/query_params/parse_whatwg_success_trailing_empty_name_and_value.phpt
new file mode 100644
index 000000000000..5b7d3df365fa
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_trailing_empty_name_and_value.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - a trailing empty name and value is preserved
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "foo"
+ [1]=>
+ string(3) "bar"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(0) ""
+ }
+}
+string(9) "foo=bar&="
+string(9) "foo=bar&="
+string(9) "foo=bar&="
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_utf8_bom.phpt b/ext/uri/tests/query_params/parse_whatwg_success_utf8_bom.phpt
new file mode 100644
index 000000000000..7697e256b021
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_utf8_bom.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - UTF-8 bom
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "%r\xEF\xBB\xBF\x61%r"
+ [1]=>
+ string(4) "%r\xEF\xBB\xBF\x62%r"
+ }
+}
+string(21) "%EF%BB%BFa=%EF%BB%BFb"
+string(21) "%EF%BB%BFa=%EF%BB%BFb"
+string(21) "%EF%BB%BFa=%EF%BB%BFb"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_utf8_incomplete.phpt b/ext/uri/tests/query_params/parse_whatwg_success_utf8_incomplete.phpt
new file mode 100644
index 000000000000..1728fd909ec4
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_utf8_incomplete.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - incomplete percent-encoded UTF-8
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "a�"
+ [1]=>
+ string(4) "b�"
+ }
+}
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_utf8_incomplete_raw.phpt b/ext/uri/tests/query_params/parse_whatwg_success_utf8_incomplete_raw.phpt
new file mode 100644
index 000000000000..e12bb9e4f3db
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_utf8_incomplete_raw.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - UTF-8 incomplete raw
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "a�"
+ [1]=>
+ string(4) "b�"
+ }
+}
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
+string(21) "a%EF%BF%BD=b%EF%BF%BD"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_utf8_invalid.phpt b/ext/uri/tests/query_params/parse_whatwg_success_utf8_invalid.phpt
new file mode 100644
index 000000000000..d7201683ef00
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_utf8_invalid.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - invalid percent-encoded UTF-8
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "a�z"
+ [1]=>
+ string(5) "b�y"
+ }
+}
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_utf8_invalid_raw.phpt b/ext/uri/tests/query_params/parse_whatwg_success_utf8_invalid_raw.phpt
new file mode 100644
index 000000000000..25eb90cb35b3
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_utf8_invalid_raw.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - UTF-8 invalid raw
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "a�z"
+ [1]=>
+ string(5) "b�y"
+ }
+}
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
+string(23) "a%EF%BF%BDz=b%EF%BF%BDy"
diff --git a/ext/uri/tests/query_params/parse_whatwg_success_utf8_valid.phpt b/ext/uri/tests/query_params/parse_whatwg_success_utf8_valid.phpt
new file mode 100644
index 000000000000..d0b7586b87c5
--- /dev/null
+++ b/ext/uri/tests/query_params/parse_whatwg_success_utf8_valid.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test Uri\QueryParams::parseWhatWgUrlSearchParams() - success - UTF-8 valid
+--FILE--
+toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(11) "aé€😀z"
+ [1]=>
+ string(11) "bé€😀y"
+ }
+}
+string(59) "a%C3%A9%E2%82%AC%F0%9F%98%80z=b%C3%A9%E2%82%AC%F0%9F%98%80y"
+string(59) "a%C3%A9%E2%82%AC%F0%9F%98%80z=b%C3%A9%E2%82%AC%F0%9F%98%80y"
+string(59) "a%C3%A9%E2%82%AC%F0%9F%98%80z=b%C3%A9%E2%82%AC%F0%9F%98%80y"
diff --git a/ext/uri/tests/query_params/serialize_success_basic.phpt b/ext/uri/tests/query_params/serialize_success_basic.phpt
new file mode 100644
index 000000000000..52b0017eee65
--- /dev/null
+++ b/ext/uri/tests/query_params/serialize_success_basic.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Test Uri\QueryParams serialization - success - duplicate names and deleted entries
+--FILE--
+delete("discard");
+$params2 = unserialize(serialize($params1));
+
+var_dump($params1 === $params2);
+var_dump($params2->toList() === $params1->toList());
+var_dump($params2->getAll("x"));
+var_dump($params2->count());
+
+$params2 = $params2->append("x", "3")->set("flag", "yes")->deleteValue("x", "1");
+var_dump($params1->toRfc3986String());
+var_dump($params2->toRfc3986String());
+var_dump($params2->getFirst("x"));
+var_dump($params2->getLast("x"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+bool(true)
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+}
+int(4)
+string(19) "x=1&flag&x=2&empty="
+string(23) "flag=yes&x=2&empty=&x=3"
+string(1) "2"
+string(1) "3"
+int(4)
diff --git a/ext/uri/tests/query_params/serialize_success_data.phpt b/ext/uri/tests/query_params/serialize_success_data.phpt
new file mode 100644
index 000000000000..28378adbb9cd
--- /dev/null
+++ b/ext/uri/tests/query_params/serialize_success_data.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams::__serialize() - success - independent list snapshot and empty properties
+--FILE--
+__serialize();
+$data[0]["params"][0][1] = "changed";
+
+var_dump($params1->toRfc3986String());
+
+$data = $params1->__serialize();
+unset($params1);
+var_dump($data[0]);
+var_dump($data[1]);
+
+?>
+--EXPECT--
+string(5) "x=1&x"
+array(1) {
+ ["params"]=>
+ array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ NULL
+ }
+ }
+}
+array(0) {
+}
diff --git a/ext/uri/tests/query_params/serialize_success_empty.phpt b/ext/uri/tests/query_params/serialize_success_empty.phpt
new file mode 100644
index 000000000000..6b0565dbc2ff
--- /dev/null
+++ b/ext/uri/tests/query_params/serialize_success_empty.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams serialization - success - empty list
+--FILE--
+toList());
+var_dump($params2->count());
+$params2 = $params2->append("x", "1");
+var_dump($params2->toRfc3986String());
+
+?>
+--EXPECT--
+array(0) {
+}
+int(0)
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/serialize_success_no_parsing_limits.phpt b/ext/uri/tests/query_params/serialize_success_no_parsing_limits.phpt
new file mode 100644
index 000000000000..aaded3f320af
--- /dev/null
+++ b/ext/uri/tests/query_params/serialize_success_no_parsing_limits.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams serialization - success - the parsing parameter count limit does not apply
+--FILE--
+toList() === $params1->toList());
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(true)
+int(1001)
diff --git a/ext/uri/tests/query_params/serialize_success_raw_values.phpt b/ext/uri/tests/query_params/serialize_success_raw_values.phpt
new file mode 100644
index 000000000000..c29b9861b6e1
--- /dev/null
+++ b/ext/uri/tests/query_params/serialize_success_raw_values.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Test Uri\QueryParams serialization - success - preserve empty fields and arbitrary bytes
+--FILE--
+append("", null)->append("", "")->append("a\0b%FF", "\xFF\0%20\r\n");
+$params2 = unserialize(serialize($params1));
+
+var_dump($params2->toList() === $params1->toList());
+var_dump($params2->getAll(""));
+var_dump(bin2hex($params2->getFirst("a\0b%FF")));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ [0]=>
+ NULL
+ [1]=>
+ string(0) ""
+}
+string(14) "ff002532300d0a"
+int(3)
diff --git a/ext/uri/tests/query_params/set_error_bool.phpt b/ext/uri/tests/query_params/set_error_bool.phpt
new file mode 100644
index 000000000000..5883e728f4c4
--- /dev/null
+++ b/ext/uri/tests/query_params/set_error_bool.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::set() - error - boolean value
+--FILE--
+set("x", false);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::set(): Argument #2 ($value) must be of type BackedEnum|string|int|float|null, false given
diff --git a/ext/uri/tests/query_params/set_error_float_non_finite.phpt b/ext/uri/tests/query_params/set_error_float_non_finite.phpt
new file mode 100644
index 000000000000..e3879a9a7b02
--- /dev/null
+++ b/ext/uri/tests/query_params/set_error_float_non_finite.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::set() - error - non-finite float leaves the original unchanged
+--FILE--
+append("x", "1");
+
+try {
+ $params2 = $params1->set("x", INF);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params1->toRfc3986String());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::set(): Argument #2 ($value) must be finite
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/set_success_compaction_single.phpt b/ext/uri/tests/query_params/set_success_compaction_single.phpt
new file mode 100644
index 000000000000..ee582b766b43
--- /dev/null
+++ b/ext/uri/tests/query_params/set_success_compaction_single.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Test Uri\QueryParams::set() - success - compacting to a single entry
+--FILE--
+set("x", "2");
+
+var_dump($params1->count());
+var_dump($params1->getFirst("x"));
+var_dump($params2->toRfc3986String());
+var_dump($params2->count());
+var_dump($params2->getFirst("x"));
+var_dump($params2->getLast("x"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+$params2 = $params2->append("x", "3");
+var_dump($params2->toRfc3986String());
+var_dump($params2->getAll("x"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+?>
+--EXPECT--
+int(102)
+string(1) "1"
+string(3) "x=2"
+int(1)
+string(1) "2"
+string(1) "2"
+bool(true)
+string(7) "x=2&x=3"
+array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(1) "3"
+}
+bool(true)
diff --git a/ext/uri/tests/query_params/set_success_immutable.phpt b/ext/uri/tests/query_params/set_success_immutable.phpt
new file mode 100644
index 000000000000..bcc1ae348e40
--- /dev/null
+++ b/ext/uri/tests/query_params/set_success_immutable.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::set() - success - the original instance is unchanged
+--FILE--
+set("x", 3);
+
+var_dump($params1 === $params2);
+var_dump($params1->toRfc3986String());
+var_dump($params1->getFirst("x"));
+var_dump($params1->getLast("x"));
+var_dump($params2->toRfc3986String());
+var_dump($params2->getFirst("x"));
+var_dump($params2->getLast("x"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+string(12) "x=1&x=2&flag"
+string(1) "1"
+string(1) "2"
+string(8) "x=3&flag"
+string(1) "3"
+string(1) "3"
+int(2)
diff --git a/ext/uri/tests/query_params/set_success_missing_key.phpt b/ext/uri/tests/query_params/set_success_missing_key.phpt
new file mode 100644
index 000000000000..1d8399d3c592
--- /dev/null
+++ b/ext/uri/tests/query_params/set_success_missing_key.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::set() - success - a missing name is appended to the new instance
+--FILE--
+set("flag", null);
+
+var_dump($params1->toRfc3986String());
+var_dump($params1->has("flag"));
+var_dump($params2->toRfc3986String());
+var_dump($params2->has("flag"));
+
+?>
+--EXPECT--
+string(3) "x=1"
+bool(false)
+string(8) "x=1&flag"
+bool(true)
diff --git a/ext/uri/tests/query_params/set_success_weak_types.phpt b/ext/uri/tests/query_params/set_success_weak_types.phpt
new file mode 100644
index 000000000000..50db0e592897
--- /dev/null
+++ b/ext/uri/tests/query_params/set_success_weak_types.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::set() - success - weak boolean and Stringable conversion
+--FILE--
+set("a", false)->set("b", true)->set("c", new Value());
+
+var_dump($params1->toRfc3986String());
+var_dump($params2->toRfc3986String());
+
+?>
+--EXPECT--
+string(17) "a=old&b=old&c=old"
+string(14) "a=0&b=1&c=0012"
diff --git a/ext/uri/tests/query_params/sort_by_bytes_success_basic.phpt b/ext/uri/tests/query_params/sort_by_bytes_success_basic.phpt
new file mode 100644
index 000000000000..d98db1546792
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_bytes_success_basic.phpt
@@ -0,0 +1,49 @@
+--TEST--
+Test Uri\QueryParams::sortByBytes() - success - stable, case-sensitive sorting and immutability
+--FILE--
+append("z", "6")->append("b", "6")->append("A", "upper")->append("10", "ten")
+ ->append("z", "5")->append("b", "5")->append("2", "two")
+ ->append("z", "4")->append("b", "4")->append("z", "3")->append("b", "3")
+ ->append("z", "2")->append("b", "2")->append("z", "1")->append("b", "1")
+ ->append("a", "lower")->append("B", "upper")->append("0", "zero")->append("b", null);
+$params2 = $params1->sortByBytes();
+
+var_dump($params1 === $params2);
+var_dump($params1->toRfc3986String());
+var_dump($params2->toRfc3986String());
+var_dump($params2->count());
+var_dump($params2->getAll("b"));
+var_dump($params2->getFirst("b"));
+var_dump($params2->getLast("b"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+var_dump($params2->sortByBytes()->toRfc3986String());
+
+?>
+--EXPECT--
+bool(false)
+string(93) "z=6&b=6&A=upper&10=ten&z=5&b=5&2=two&z=4&b=4&z=3&b=3&z=2&b=2&z=1&b=1&a=lower&B=upper&0=zero&b"
+string(93) "0=zero&10=ten&2=two&A=upper&B=upper&a=lower&b=6&b=5&b=4&b=3&b=2&b=1&b&z=6&z=5&z=4&z=3&z=2&z=1"
+int(19)
+array(7) {
+ [0]=>
+ string(1) "6"
+ [1]=>
+ string(1) "5"
+ [2]=>
+ string(1) "4"
+ [3]=>
+ string(1) "3"
+ [4]=>
+ string(1) "2"
+ [5]=>
+ string(1) "1"
+ [6]=>
+ NULL
+}
+string(1) "6"
+NULL
+bool(true)
+string(93) "0=zero&10=ten&2=two&A=upper&B=upper&a=lower&b=6&b=5&b=4&b=3&b=2&b=1&b&z=6&z=5&z=4&z=3&z=2&z=1"
diff --git a/ext/uri/tests/query_params/sort_by_bytes_success_binary.phpt b/ext/uri/tests/query_params/sort_by_bytes_success_binary.phpt
new file mode 100644
index 000000000000..6d2637ebac1b
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_bytes_success_binary.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test Uri\QueryParams::sortByBytes() - success - binary names and values
+--FILE--
+append("\xFF", "first")
+ ->append("\u{FFFD}", "literal")
+ ->append("\xE2\x82", "incomplete")
+ ->append("\x80", "continuation")
+ ->append("\xE2a", "bad-tail")
+ ->append("\xED\xA0\x80", "surrogate")
+ ->append("\xF4\x90\x80\x80", "out-of-range")
+ ->append("\0z", "nul-z")
+ ->append("\0a", "nul-a")
+ ->append("", "empty")
+ ->append("\u{FEFF}", "bom")
+ ->append("a", "\xFF")
+ ->append("\u{10000}", "supplementary")
+ ->append("\xFF", null);
+$params2 = $params1->sortByBytes();
+
+var_dump($params2->toRfc3986String());
+var_dump($params2->getAll("\xFF"));
+var_dump($params2->getAll("\u{FFFD}"));
+var_dump($params2->getAll("\xE2\x82"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+?>
+--EXPECT--
+string(202) "=empty&%00a=nul-a&%00z=nul-z&a=%FF&%80=continuation&%E2a=bad-tail&%E2%82=incomplete&%ED%A0%80=surrogate&%EF%BB%BF=bom&%EF%BF%BD=literal&%F0%90%80%80=supplementary&%F4%90%80%80=out-of-range&%FF=first&%FF"
+array(2) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ NULL
+}
+array(1) {
+ [0]=>
+ string(7) "literal"
+}
+array(1) {
+ [0]=>
+ string(10) "incomplete"
+}
+bool(true)
diff --git a/ext/uri/tests/query_params/sort_by_bytes_success_empty.phpt b/ext/uri/tests/query_params/sort_by_bytes_success_empty.phpt
new file mode 100644
index 000000000000..163a20cf0b1d
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_bytes_success_empty.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Test Uri\QueryParams::sortByBytes() - success - empty and fully deleted lists
+--FILE--
+sortByBytes();
+
+var_dump($params1 === $params2);
+var_dump($params2->toList());
+var_dump($params2->count());
+
+$params1 = (new Uri\QueryParams())->append("x", "1")->append("x", "2")->delete("x");
+$params2 = $params1->sortByBytes();
+var_dump($params2->toList());
+var_dump($params2->count());
+
+$params2 = $params2->append("z", "3")->append("a", "4");
+var_dump($params1->toList());
+var_dump($params2->toList());
+var_dump(iterator_to_array($params2) === $params2->toList());
+var_dump($params2->getFirst("z"));
+var_dump($params2->getLast("a"));
+
+?>
+--EXPECT--
+bool(false)
+array(0) {
+}
+int(0)
+array(0) {
+}
+int(0)
+array(0) {
+}
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "z"
+ [1]=>
+ string(1) "3"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "4"
+ }
+}
+bool(true)
+string(1) "3"
+string(1) "4"
diff --git a/ext/uri/tests/query_params/sort_by_bytes_success_tombstones.phpt b/ext/uri/tests/query_params/sort_by_bytes_success_tombstones.phpt
new file mode 100644
index 000000000000..defee8193ce2
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_bytes_success_tombstones.phpt
@@ -0,0 +1,76 @@
+--TEST--
+Test Uri\QueryParams::sortByBytes() - success - deleted entries and lookup indices
+--FILE--
+append("gone", "0")->append("z", "first")->append("a", "only")
+ ->append("z", "removed")->append("b", "only")->append("z", "last")
+ ->delete("gone")->deleteValue("z", "removed");
+$iterator = $params1->getIterator();
+$params2 = $params1->sortByBytes();
+
+var_dump($params1->toRfc3986String());
+var_dump($params2->toRfc3986String());
+var_dump(iterator_to_array($iterator) === $params1->toList());
+var_dump(iterator_to_array($params2) === $params2->toList());
+var_dump($params2->count());
+var_dump($params2->has("gone"));
+var_dump($params2->getFirst("z"));
+var_dump($params2->getLast("z"));
+var_dump($params2->getAll("z"));
+
+$params2 = $params2->append("z", "appended");
+var_dump($params2->getAll("z"));
+$params2 = $params2->deleteValue("z", "first");
+var_dump($params2->getFirst("z"));
+$params2 = $params2->set("z", "replaced");
+var_dump($params2->toRfc3986String());
+$params2 = $params2->delete("z")->delete("a")->sortByBytes();
+var_dump($params2->toList());
+$params2 = $params2->append("b", "second");
+var_dump($params2->getAll("b"));
+var_dump(iterator_to_array($params2) === $params2->toList());
+
+?>
+--EXPECT--
+string(28) "z=first&a=only&b=only&z=last"
+string(28) "a=only&b=only&z=first&z=last"
+bool(true)
+bool(true)
+int(4)
+bool(false)
+string(5) "first"
+string(4) "last"
+array(2) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ string(4) "last"
+}
+array(3) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ string(4) "last"
+ [2]=>
+ string(8) "appended"
+}
+string(4) "last"
+string(24) "a=only&b=only&z=replaced"
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "b"
+ [1]=>
+ string(4) "only"
+ }
+}
+array(2) {
+ [0]=>
+ string(4) "only"
+ [1]=>
+ string(6) "second"
+}
+bool(true)
diff --git a/ext/uri/tests/query_params/sort_by_bytes_success_utf8.phpt b/ext/uri/tests/query_params/sort_by_bytes_success_utf8.phpt
new file mode 100644
index 000000000000..290f0570deb7
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_bytes_success_utf8.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test Uri\QueryParams::sortByBytes() - success - Unicode order, surrogate pairs and prefixes
+--FILE--
+append("\u{E000}", "private")
+ ->append("\u{1F601}", "grin")
+ ->append("\u{1F600}a", "smile-prefix")
+ ->append("\u{10000}", "supplementary")
+ ->append("\u{1F600}", "smile")
+ ->append("\u{FFFF}", "last-bmp")
+ ->append("\u{FEFF}", "bom")
+ ->append("\u{E9}", "composed")
+ ->append("e\u{301}", "decomposed")
+ ->append("\u{D7FF}", "before-surrogates");
+$params2 = $params1->sortByBytes();
+
+var_dump($params2->toRfc3986String());
+
+?>
+--EXPECT--
+string(204) "e%CC%81=decomposed&%C3%A9=composed&%ED%9F%BF=before-surrogates&%EE%80%80=private&%EF%BB%BF=bom&%EF%BF%BF=last-bmp&%F0%90%80%80=supplementary&%F0%9F%98%80=smile&%F0%9F%98%80a=smile-prefix&%F0%9F%98%81=grin"
diff --git a/ext/uri/tests/query_params/sort_by_bytes_success_weak_reference.phpt b/ext/uri/tests/query_params/sort_by_bytes_success_weak_reference.phpt
new file mode 100644
index 000000000000..5372a40b05fc
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_bytes_success_weak_reference.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Test Uri\QueryParams::sortByBytes() - success - a weakly referenced temporary instance is cloned
+--FILE--
+append("z", "1")->append("a", "2");
+ $reference = WeakReference::create($params1);
+ return $params1;
+}
+
+$params2 = createParams($reference)->sortByBytes();
+
+var_dump($reference->get());
+var_dump($params2->toList());
+var_dump($params2->toRfc3986String());
+
+?>
+--EXPECT--
+NULL
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "2"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "z"
+ [1]=>
+ string(1) "1"
+ }
+}
+string(7) "a=2&z=1"
diff --git a/ext/uri/tests/query_params/sort_by_utf16_success_invalid_utf8.phpt b/ext/uri/tests/query_params/sort_by_utf16_success_invalid_utf8.phpt
new file mode 100644
index 000000000000..cdc41aa88232
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_utf16_success_invalid_utf8.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test Uri\QueryParams::sortByUtf16() - malformed UTF-8 compares as U+FFFD and original bytes are preserved
+--FILE--
+append("\xE2z", "tail")
+ ->append("\xFF", "first")
+ ->append("\u{FFFD}", "literal")
+ ->append("\xE2\x82", "incomplete")
+ ->append("\u{10000}", "pair")
+ ->append("\xFF", "last")
+ ->append("\u{FFFD}a", "suffix");
+$params2 = $params1->sortByUtf16();
+
+var_dump($params2->toRfc3986String());
+var_dump($params2->getAll("\xFF"));
+var_dump($params2->getFirst("\u{FFFD}"));
+
+?>
+--EXPECT--
+string(100) "%F0%90%80%80=pair&%FF=first&%EF%BF%BD=literal&%E2%82=incomplete&%FF=last&%EF%BF%BDa=suffix&%E2z=tail"
+array(2) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ string(4) "last"
+}
+string(7) "literal"
diff --git a/ext/uri/tests/query_params/sort_by_utf16_success_nul.phpt b/ext/uri/tests/query_params/sort_by_utf16_success_nul.phpt
new file mode 100644
index 000000000000..9632420e076f
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_utf16_success_nul.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test Uri\QueryParams::sortByUtf16() - embedded NUL, prefixes and stable duplicate names
+--FILE--
+append("a\0b", "z")
+ ->append("a\0a", "2")
+ ->append("a\0b", "a")
+ ->append("a\0", "3")
+ ->append("a", "4")
+ ->append("", "5");
+$params2 = $params1->sortByUtf16();
+
+var_dump($params1->toRfc3986String());
+var_dump($params2->toRfc3986String());
+var_dump($params2->getAll("a\0b"));
+
+?>
+--EXPECT--
+string(37) "a%00b=z&a%00a=2&a%00b=a&a%00=3&a=4&=5"
+string(37) "=5&a=4&a%00=3&a%00a=2&a%00b=z&a%00b=a"
+array(2) {
+ [0]=>
+ string(1) "z"
+ [1]=>
+ string(1) "a"
+}
diff --git a/ext/uri/tests/query_params/sort_by_utf16_success_unicode.phpt b/ext/uri/tests/query_params/sort_by_utf16_success_unicode.phpt
new file mode 100644
index 000000000000..9dd36fedcac2
--- /dev/null
+++ b/ext/uri/tests/query_params/sort_by_utf16_success_unicode.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::sortByUtf16() - UTF-16 code unit order across the surrogate range
+--FILE--
+append("p\u{FF5E}", "tilde")
+ ->append("p\u{1F600}a", "prefix")
+ ->append("p\u{10FFFF}", "last")
+ ->append("p\u{E000}", "private")
+ ->append("p\u{1F601}", "grin")
+ ->append("p\u{10000}", "first")
+ ->append("p\u{D7FF}", "before")
+ ->append("p\u{1F600}", "smile")
+ ->append("p", "ascii");
+$params2 = $params1->sortByUtf16();
+
+var_dump(array_column($params2->toList(), 1));
+
+?>
+--EXPECT--
+array(9) {
+ [0]=>
+ string(5) "ascii"
+ [1]=>
+ string(6) "before"
+ [2]=>
+ string(5) "first"
+ [3]=>
+ string(5) "smile"
+ [4]=>
+ string(6) "prefix"
+ [5]=>
+ string(4) "grin"
+ [6]=>
+ string(4) "last"
+ [7]=>
+ string(7) "private"
+ [8]=>
+ string(5) "tilde"
+}
diff --git a/ext/uri/tests/query_params/to_array_error_append_overflow.phpt b/ext/uri/tests/query_params/to_array_error_append_overflow.phpt
new file mode 100644
index 000000000000..5319edfb7ef5
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_append_overflow.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - appending beyond the largest integer key
+--FILE--
+append("k[" . PHP_INT_MAX . "]", "1")->append("k[]", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: Cannot append an array element for query parameter "k[]"
diff --git a/ext/uri/tests/query_params/to_array_error_array_then_scalar.phpt b/ext/uri/tests/query_params/to_array_error_array_then_scalar.phpt
new file mode 100644
index 000000000000..2e7474b7c3ef
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_array_then_scalar.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - array then scalar
+--FILE--
+append("k[a][b]", "1")->append("k[a]", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[a]" has conflicting array paths
diff --git a/ext/uri/tests/query_params/to_array_error_brackets_then_plain.phpt b/ext/uri/tests/query_params/to_array_error_brackets_then_plain.phpt
new file mode 100644
index 000000000000..425df30aaa2b
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_brackets_then_plain.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - brackets then plain
+--FILE--
+append("k[]", "1")->append("k", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[]" has conflicting array paths
diff --git a/ext/uri/tests/query_params/to_array_error_default_nesting_limit.phpt b/ext/uri/tests/query_params/to_array_error_default_nesting_limit.phpt
new file mode 100644
index 000000000000..0382d5fdf103
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_default_nesting_limit.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - depth beyond the default limit
+--FILE--
+append($name, "value");
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a][a]" exceeds the maximum nesting level of 64
diff --git a/ext/uri/tests/query_params/to_array_error_duplicate_leaf.phpt b/ext/uri/tests/query_params/to_array_error_duplicate_leaf.phpt
new file mode 100644
index 000000000000..100a04ab2697
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_duplicate_leaf.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - duplicate leaf
+--FILE--
+append("k[a]", "1")->append("k[a]", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[a]" has conflicting array paths
diff --git a/ext/uri/tests/query_params/to_array_error_duplicate_null_leaf.phpt b/ext/uri/tests/query_params/to_array_error_duplicate_null_leaf.phpt
new file mode 100644
index 000000000000..b92ef84058bd
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_duplicate_null_leaf.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - null is an occupied leaf
+--FILE--
+append("k[a]", null)->append("k[a]", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[a]" has conflicting array paths
diff --git a/ext/uri/tests/query_params/to_array_error_implicit_then_explicit.phpt b/ext/uri/tests/query_params/to_array_error_implicit_then_explicit.phpt
new file mode 100644
index 000000000000..cc0f5e2d6510
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_implicit_then_explicit.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - implicit then explicit
+--FILE--
+append("k[]", "1")->append("k[0]", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[0]" has conflicting array paths
diff --git a/ext/uri/tests/query_params/to_array_error_negative_nesting_level.phpt b/ext/uri/tests/query_params/to_array_error_negative_nesting_level.phpt
new file mode 100644
index 000000000000..592546b5a4e4
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_negative_nesting_level.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - negative nesting level
+--FILE--
+toArray(-1);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::toArray(): Argument #1 ($maxNestingLevel) must be greater than or equal to 0
diff --git a/ext/uri/tests/query_params/to_array_error_nesting_limit.phpt b/ext/uri/tests/query_params/to_array_error_nesting_limit.phpt
new file mode 100644
index 000000000000..7370c5e62451
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_nesting_limit.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - nesting limit
+--FILE--
+append("k[a][b]", "1");
+
+try {
+ $params->toArray(1);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[a][b]" exceeds the maximum nesting level of 1
diff --git a/ext/uri/tests/query_params/to_array_error_plain_then_brackets.phpt b/ext/uri/tests/query_params/to_array_error_plain_then_brackets.phpt
new file mode 100644
index 000000000000..388ee157ec3b
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_plain_then_brackets.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - plain then brackets
+--FILE--
+append("k", "1")->append("k[]", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[]" has conflicting array paths
diff --git a/ext/uri/tests/query_params/to_array_error_scalar_then_array.phpt b/ext/uri/tests/query_params/to_array_error_scalar_then_array.phpt
new file mode 100644
index 000000000000..adaf64ffdeb3
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_scalar_then_array.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - scalar then array
+--FILE--
+append("k[a]", "1")->append("k[a][b]", "2");
+
+try {
+ $params->toArray();
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[a][b]" has conflicting array paths
diff --git a/ext/uri/tests/query_params/to_array_error_zero_nesting_level_brackets.phpt b/ext/uri/tests/query_params/to_array_error_zero_nesting_level_brackets.phpt
new file mode 100644
index 000000000000..a3a6bc4305e0
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_zero_nesting_level_brackets.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - zero nesting level brackets
+--FILE--
+append("k[]", "1");
+
+try {
+ $params->toArray(0);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k[]" exceeds the maximum nesting level of 0
diff --git a/ext/uri/tests/query_params/to_array_error_zero_nesting_level_repeated_names.phpt b/ext/uri/tests/query_params/to_array_error_zero_nesting_level_repeated_names.phpt
new file mode 100644
index 000000000000..4521d81eecd0
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_error_zero_nesting_level_repeated_names.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - error - zero nesting level repeated names
+--FILE--
+append("k", "1")->append("k", "2");
+
+try {
+ $params->toArray(0);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+Uri\InvalidQueryParamsException: The query parameter "k" exceeds the maximum nesting level of 0
diff --git a/ext/uri/tests/query_params/to_array_success_binary.phpt b/ext/uri/tests/query_params/to_array_success_binary.phpt
new file mode 100644
index 000000000000..4c149f9488b2
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_binary.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - NUL bytes and non-UTF-8 bytes are preserved
+--FILE--
+append("\0root[\0key]", "\0\xff")->append("bad[\0", null);
+
+var_dump($params->toArray() === ["\0root" => ["\0key" => "\0\xff"], "bad[\0" => null]);
+
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/uri/tests/query_params/to_array_success_default_nesting_limit.phpt b/ext/uri/tests/query_params/to_array_success_default_nesting_limit.phpt
new file mode 100644
index 000000000000..7c152c138875
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_default_nesting_limit.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - the default nesting limit is inclusive
+--FILE--
+append($name, "value");
+$array = $params->toArray();
+for ($depth = 0; is_array($array); $depth++) {
+ $array = reset($array);
+}
+var_dump($depth, $array);
+
+?>
+--EXPECT--
+int(65)
+string(5) "value"
diff --git a/ext/uri/tests/query_params/to_array_success_empty.phpt b/ext/uri/tests/query_params/to_array_success_empty.phpt
new file mode 100644
index 000000000000..397a53c0e319
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_empty.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - empty list
+--FILE--
+toArray());
+
+?>
+--EXPECT--
+array(0) {
+}
diff --git a/ext/uri/tests/query_params/to_array_success_empty_root.phpt b/ext/uri/tests/query_params/to_array_success_empty_root.phpt
new file mode 100644
index 000000000000..a36be4d6dfc2
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_empty_root.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - empty root and bracket keys
+--FILE--
+append("[a]", "1")->append("[]", "2");
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(1) {
+ [""]=>
+ array(2) {
+ ["a"]=>
+ string(1) "1"
+ [0]=>
+ string(1) "2"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_explicit_and_implicit_indices.phpt b/ext/uri/tests/query_params/to_array_success_explicit_and_implicit_indices.phpt
new file mode 100644
index 000000000000..b840117fb37f
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_explicit_and_implicit_indices.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - appending after an explicit index
+--FILE--
+append("k[2]", "a")->append("k[]", "b");
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["k"]=>
+ array(2) {
+ [2]=>
+ string(1) "a"
+ [3]=>
+ string(1) "b"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_malformed_brackets.phpt b/ext/uri/tests/query_params/to_array_success_malformed_brackets.phpt
new file mode 100644
index 000000000000..de10213299a7
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_malformed_brackets.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - malformed names are interpreted entirely literally
+--FILE--
+append("k[", "1")->append("k[", "2")->append("foo[]]", "3")->append("foo[[a]", "4")->append("foo[a]tail", "5")->append("foo][a]", "6")->append("foo[a][", "7");
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(6) {
+ ["k["]=>
+ array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+ }
+ ["foo[]]"]=>
+ string(1) "3"
+ ["foo[[a]"]=>
+ string(1) "4"
+ ["foo[a]tail"]=>
+ string(1) "5"
+ ["foo][a]"]=>
+ string(1) "6"
+ ["foo[a]["]=>
+ string(1) "7"
+}
diff --git a/ext/uri/tests/query_params/to_array_success_multi_dimension.phpt b/ext/uri/tests/query_params/to_array_success_multi_dimension.phpt
new file mode 100644
index 000000000000..e1def16887be
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_multi_dimension.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - multi-dimension array
+--FILE--
+toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["foo"]=>
+ array(2) {
+ ["bar"]=>
+ array(1) {
+ ["baz"]=>
+ string(3) "123"
+ }
+ ["qux"]=>
+ string(4) "quux"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_multiple_keys_with_brackets.phpt b/ext/uri/tests/query_params/to_array_success_multiple_keys_with_brackets.phpt
new file mode 100644
index 000000000000..db75abc5ef6f
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_multiple_keys_with_brackets.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - multiple keys, using brackets
+--FILE--
+toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["abc"]=>
+ array(2) {
+ [0]=>
+ string(3) "123"
+ [1]=>
+ string(3) "456"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_multiple_keys_without_brackets.phpt b/ext/uri/tests/query_params/to_array_success_multiple_keys_without_brackets.phpt
new file mode 100644
index 000000000000..c65e35d89358
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_multiple_keys_without_brackets.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - multiple keys, without brackets
+--FILE--
+toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["abc"]=>
+ array(2) {
+ [0]=>
+ string(3) "123"
+ [1]=>
+ string(3) "456"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_negative_index.phpt b/ext/uri/tests/query_params/to_array_success_negative_index.phpt
new file mode 100644
index 000000000000..e95b093ae463
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_negative_index.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - normal PHP append semantics after a negative index
+--FILE--
+append("k[-5]", "a")->append("k[]", "b");
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["k"]=>
+ array(2) {
+ [-5]=>
+ string(1) "a"
+ [-4]=>
+ string(1) "b"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_nested_empty_brackets.phpt b/ext/uri/tests/query_params/to_array_success_nested_empty_brackets.phpt
new file mode 100644
index 000000000000..d7a3f242632c
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_nested_empty_brackets.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - empty brackets create a new nested array for each occurrence
+--FILE--
+append("k[][a]", "1")->append("k[][b]", "2");
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["k"]=>
+ array(2) {
+ [0]=>
+ array(1) {
+ ["a"]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(1) {
+ ["b"]=>
+ string(1) "2"
+ }
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_nesting_limit.phpt b/ext/uri/tests/query_params/to_array_success_nesting_limit.phpt
new file mode 100644
index 000000000000..930e018041aa
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_nesting_limit.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - nesting depth exactly at the limit
+--FILE--
+append("k[a][b]", "1");
+
+var_dump($params->toArray(2));
+
+?>
+--EXPECT--
+array(1) {
+ ["k"]=>
+ array(1) {
+ ["a"]=>
+ array(1) {
+ ["b"]=>
+ string(1) "1"
+ }
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_null.phpt b/ext/uri/tests/query_params/to_array_success_null.phpt
new file mode 100644
index 000000000000..22f9af002814
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_null.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - null values are preserved in scalars and arrays
+--FILE--
+append("scalar", null)->append("list", null)->append("list", "value")->append("nested[a]", null)->append("brackets[]", null);
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(4) {
+ ["scalar"]=>
+ NULL
+ ["list"]=>
+ array(2) {
+ [0]=>
+ NULL
+ [1]=>
+ string(5) "value"
+ }
+ ["nested"]=>
+ array(1) {
+ ["a"]=>
+ NULL
+ }
+ ["brackets"]=>
+ array(1) {
+ [0]=>
+ NULL
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_numeric_keys.phpt b/ext/uri/tests/query_params/to_array_success_numeric_keys.phpt
new file mode 100644
index 000000000000..81b78fdb1065
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_numeric_keys.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - normal PHP key conversion at root and nested levels
+--FILE--
+append("1", "a")->append("1", "b")->append("01", "c")->append("+1", "d")->append("-0", "e")->append("k[1]", "a")->append("k[01]", "b")->append("k[+1]", "c")->append("k[-0]", "d")->append("k[-1]", "e")->append("k[ 1]", "f");
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(5) {
+ [1]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "b"
+ }
+ ["01"]=>
+ string(1) "c"
+ ["+1"]=>
+ string(1) "d"
+ ["-0"]=>
+ string(1) "e"
+ ["k"]=>
+ array(6) {
+ [1]=>
+ string(1) "a"
+ ["01"]=>
+ string(1) "b"
+ ["+1"]=>
+ string(1) "c"
+ ["-0"]=>
+ string(1) "d"
+ [-1]=>
+ string(1) "e"
+ [" 1"]=>
+ string(1) "f"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_one_key_with_brackets.phpt b/ext/uri/tests/query_params/to_array_success_one_key_with_brackets.phpt
new file mode 100644
index 000000000000..c05f5d610065
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_one_key_with_brackets.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - one key, using the bracket syntax
+--FILE--
+toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["abc"]=>
+ array(1) {
+ [0]=>
+ string(3) "123"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_one_key_without_brackets.phpt b/ext/uri/tests/query_params/to_array_success_one_key_without_brackets.phpt
new file mode 100644
index 000000000000..fe105deeadaf
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_one_key_without_brackets.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - one key, without brackets
+--FILE--
+toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["abc"]=>
+ string(3) "123"
+}
diff --git a/ext/uri/tests/query_params/to_array_success_tombstones.phpt b/ext/uri/tests/query_params/to_array_success_tombstones.phpt
new file mode 100644
index 000000000000..de80d17e53e2
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_tombstones.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - deleted entries do not cause conflicts or appear in arrays
+--FILE--
+append("k", "1")->append("k", "2")->append("k[a]", "3")->delete("k");
+
+var_dump($params->toArray());
+
+?>
+--EXPECT--
+array(1) {
+ ["k"]=>
+ array(1) {
+ ["a"]=>
+ string(1) "3"
+ }
+}
diff --git a/ext/uri/tests/query_params/to_array_success_zero_nesting_level.phpt b/ext/uri/tests/query_params/to_array_success_zero_nesting_level.phpt
new file mode 100644
index 000000000000..a237d2082923
--- /dev/null
+++ b/ext/uri/tests/query_params/to_array_success_zero_nesting_level.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::toArray() - success - zero allows a flat array and literal malformed names
+--FILE--
+append("a", "1")->append("k[a][", "2");
+
+var_dump($params->toArray(0));
+
+?>
+--EXPECT--
+array(2) {
+ ["a"]=>
+ string(1) "1"
+ ["k[a]["]=>
+ string(1) "2"
+}
diff --git a/ext/uri/tests/query_params/unserialize_error_invalid_data.phpt b/ext/uri/tests/query_params/unserialize_error_invalid_data.phpt
new file mode 100644
index 000000000000..1291eccea3d9
--- /dev/null
+++ b/ext/uri/tests/query_params/unserialize_error_invalid_data.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Test Uri\QueryParams unserialize() - error - invalid outer structure
+--FILE--
+getMessage(), "\n";
+ }
+}
+
+$data = (new Uri\QueryParams())->__serialize();
+
+unserializeQueryParams([]);
+unserializeQueryParams([$data[0], $data[1], []]);
+unserializeQueryParams([1 => $data[0], 2 => $data[1]]);
+unserializeQueryParams([null, $data[1]]);
+unserializeQueryParams([$data[0], null]);
+unserializeQueryParams([$data[0], ["extra" => "value"]]);
+unserializeQueryParams([[], $data[1]]);
+unserializeQueryParams([["query" => "a=1"], $data[1]]);
+unserializeQueryParams([["params" => [], "extra" => []], $data[1]]);
+unserializeQueryParams([["params" => "a=1"], $data[1]]);
+unserializeQueryParams([["params" => [1 => ["a", "1"]]], $data[1]]);
+
+?>
+--EXPECT--
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
diff --git a/ext/uri/tests/query_params/unserialize_error_invalid_pairs.phpt b/ext/uri/tests/query_params/unserialize_error_invalid_pairs.phpt
new file mode 100644
index 000000000000..09604316c640
--- /dev/null
+++ b/ext/uri/tests/query_params/unserialize_error_invalid_pairs.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Test Uri\QueryParams unserialize() - error - malformed pairs and unsupported stored types
+--FILE--
+getMessage(), "\n";
+ }
+}
+
+$data = (new Uri\QueryParams())->__serialize();
+
+unserializeQueryParams([["params" => ["a=1"]], $data[1]]);
+unserializeQueryParams([["params" => [["a"]]], $data[1]]);
+unserializeQueryParams([["params" => [["a", "1", "extra"]]], $data[1]]);
+unserializeQueryParams([["params" => [[1 => "a", 2 => "1"]]], $data[1]]);
+unserializeQueryParams([["params" => [[1, "value"]]], $data[1]]);
+unserializeQueryParams([["params" => [["a", true]]], $data[1]]);
+unserializeQueryParams([["params" => [["a", []]]], $data[1]]);
+unserializeQueryParams([["params" => [["a", new stdClass()]]], $data[1]]);
+unserializeQueryParams([["params" => [["valid", "value"], ["invalid", 1]]], $data[1]]);
+
+?>
+--EXPECT--
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
+Exception: Invalid serialization data for Uri\QueryParams object
diff --git a/ext/uri/tests/query_params/unserialize_error_reinitialization.phpt b/ext/uri/tests/query_params/unserialize_error_reinitialization.phpt
new file mode 100644
index 000000000000..7bc4ffde83ee
--- /dev/null
+++ b/ext/uri/tests/query_params/unserialize_error_reinitialization.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\QueryParams::__unserialize() - error - reinitialization
+--FILE--
+__unserialize($params2->__serialize());
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params1->toRfc3986String());
+
+?>
+--EXPECT--
+Exception: Invalid serialization data for Uri\QueryParams object
+string(3) "x=1"
diff --git a/ext/uri/tests/query_params/with_array_error_bool.phpt b/ext/uri/tests/query_params/with_array_error_bool.phpt
new file mode 100644
index 000000000000..682ae59a0297
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_error_bool.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::withArray() - error - nested boolean leaves the original unchanged
+--FILE--
+withArray(["new" => 3, "bad" => [false]]);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+var_dump($params->toList());
+var_dump($params->getAll("old"));
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::withArray(): Argument #1 ($queryParams) contains an invalid value for query parameter "bad[]": expected BackedEnum|string|int|float|null, false given
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "old"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "old"
+ [1]=>
+ string(1) "2"
+ }
+}
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+}
diff --git a/ext/uri/tests/query_params/with_array_error_float_non_finite.phpt b/ext/uri/tests/query_params/with_array_error_float_non_finite.phpt
new file mode 100644
index 000000000000..3dbf9c8727bb
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_error_float_non_finite.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test Uri\QueryParams::withArray() - error - nested non-finite float leaves the original unchanged
+--FILE--
+append("old", "1");
+
+try {
+ $params2 = $params1->withArray(["new" => 2, "nested" => [-INF]]);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+var_dump($params1->toRfc3986String());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::withArray(): Argument #1 ($queryParams) contains a non-finite float for query parameter "nested[]"
+string(5) "old=1"
diff --git a/ext/uri/tests/query_params/with_array_error_object.phpt b/ext/uri/tests/query_params/with_array_error_object.phpt
new file mode 100644
index 000000000000..d72fc8afa3cb
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_error_object.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test Uri\QueryParams::withArray() - error - invalid nested value leaves the original unchanged
+--FILE--
+withArray(["new" => 3, "bad" => [new stdClass()]]);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+var_dump($params->toList());
+var_dump($params->getAll("old"));
+
+?>
+--EXPECT--
+TypeError: Uri\QueryParams::withArray(): Argument #1 ($queryParams) contains an invalid value for query parameter "bad[]": expected BackedEnum|string|int|float|null, stdClass given
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "old"
+ [1]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(3) "old"
+ [1]=>
+ string(1) "2"
+ }
+}
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+}
diff --git a/ext/uri/tests/query_params/with_array_error_recursive.phpt b/ext/uri/tests/query_params/with_array_error_recursive.phpt
new file mode 100644
index 000000000000..cf501999e66d
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_error_recursive.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Test Uri\QueryParams::withArray() - error - recursive array leaves the original unchanged
+--FILE--
+withArray($array);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), PHP_EOL;
+}
+
+var_dump($params->toList());
+
+?>
+--EXPECT--
+ValueError: Uri\QueryParams::withArray(): Argument #1 ($queryParams) must not contain recursive arrays
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "old"
+ [1]=>
+ string(1) "1"
+ }
+}
diff --git a/ext/uri/tests/query_params/with_array_success_basic.phpt b/ext/uri/tests/query_params/with_array_success_basic.phpt
new file mode 100644
index 000000000000..c70dabb6c100
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_success_basic.phpt
@@ -0,0 +1,53 @@
+--TEST--
+Test Uri\QueryParams::withArray() - success - replaces the complete list without changing the original
+--FILE--
+withArray(["new" => ["a", "b"]]);
+
+var_dump($params1 === $params2);
+var_dump($params1->toRfc3986String());
+var_dump($params2->toList());
+var_dump($params2->toArray());
+var_dump($params2->has("old"));
+var_dump($params2->getAll("new[]"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(false)
+string(18) "old=1&old=2&keep=3"
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "new[]"
+ [1]=>
+ string(1) "a"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(5) "new[]"
+ [1]=>
+ string(1) "b"
+ }
+}
+array(1) {
+ ["new"]=>
+ array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "b"
+ }
+}
+bool(false)
+array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "b"
+}
+int(2)
diff --git a/ext/uri/tests/query_params/with_array_success_empty.phpt b/ext/uri/tests/query_params/with_array_success_empty.phpt
new file mode 100644
index 000000000000..2df9d77cc720
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_success_empty.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test Uri\QueryParams::withArray() - success - clears a list containing tombstones
+--FILE--
+delete("old");
+$params2 = $params1->withArray([]);
+
+var_dump($params1->toList());
+var_dump($params2->toList());
+var_dump($params2->count());
+$params2 = $params2->append("new", "4");
+var_dump($params2->toList());
+var_dump($params2->getFirst("new"));
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "keep"
+ [1]=>
+ string(1) "3"
+ }
+}
+array(0) {
+}
+int(0)
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(3) "new"
+ [1]=>
+ string(1) "4"
+ }
+}
+string(1) "4"
diff --git a/ext/uri/tests/query_params/with_array_success_temporary.phpt b/ext/uri/tests/query_params/with_array_success_temporary.phpt
new file mode 100644
index 000000000000..923da21f8c1f
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_success_temporary.phpt
@@ -0,0 +1,50 @@
+--TEST--
+Test Uri\QueryParams::withArray() - success - reuse a temporary instance containing tombstones
+--FILE--
+append("old", "1")->append("keep", "2")->delete("old");
+ $id = spl_object_id($params1);
+ return $params1;
+}
+
+$params2 = createParams($id)->withArray(["new" => ["a", "b"]]);
+
+var_dump(spl_object_id($params2) === $id);
+var_dump($params2->toList());
+var_dump($params2->toRfc3986String());
+var_dump($params2->has("old"));
+var_dump($params2->has("keep"));
+var_dump($params2->getAll("new[]"));
+var_dump($params2->count());
+
+?>
+--EXPECT--
+bool(true)
+array(2) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(5) "new[]"
+ [1]=>
+ string(1) "a"
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ string(5) "new[]"
+ [1]=>
+ string(1) "b"
+ }
+}
+string(23) "new%5B%5D=a&new%5B%5D=b"
+bool(false)
+bool(false)
+array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "b"
+}
+int(2)
diff --git a/ext/uri/tests/query_params/with_array_success_weak_reference.phpt b/ext/uri/tests/query_params/with_array_success_weak_reference.phpt
new file mode 100644
index 000000000000..f5ed320aa678
--- /dev/null
+++ b/ext/uri/tests/query_params/with_array_success_weak_reference.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\QueryParams::withArray() - success - weak references prevent object reuse
+--FILE--
+ "1"]);
+$reference = WeakReference::create($params);
+$params = $params->withArray(["new" => "2"]);
+
+var_dump($reference->get());
+var_dump($params->getFirst("old"));
+var_dump($params->getFirst("new"));
+
+?>
+--EXPECT--
+NULL
+NULL
+string(1) "2"
diff --git a/ext/uri/tests/rfc3986/getters/query_params_success_empty.phpt b/ext/uri/tests/rfc3986/getters/query_params_success_empty.phpt
new file mode 100644
index 000000000000..1ef63ec18463
--- /dev/null
+++ b/ext/uri/tests/rfc3986/getters/query_params_success_empty.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\Rfc3986\Uri::getQueryParams() - success - a present empty query returns an empty instance
+--FILE--
+getQueryParams();
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/rfc3986/getters/query_params_success_new_instance.phpt b/ext/uri/tests/rfc3986/getters/query_params_success_new_instance.phpt
new file mode 100644
index 000000000000..ca6e8388de55
--- /dev/null
+++ b/ext/uri/tests/rfc3986/getters/query_params_success_new_instance.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test Uri\Rfc3986\Uri::getQueryParams() - success - each call creates an independent instance
+--FILE--
+getQueryParams();
+$params = $uri->getQueryParams();
+var_dump($first === $params);
+
+$first = $first->append("y", "2");
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+var_dump($uri->getRawQuery());
+
+?>
+--EXPECT--
+bool(false)
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "1"
+ }
+}
+string(3) "x=1"
+string(3) "x=1"
+string(3) "x=1"
+string(3) "x=1"
diff --git a/ext/uri/tests/rfc3986/getters/query_params_success_null.phpt b/ext/uri/tests/rfc3986/getters/query_params_success_null.phpt
new file mode 100644
index 000000000000..d13f6112a280
--- /dev/null
+++ b/ext/uri/tests/rfc3986/getters/query_params_success_null.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\Rfc3986\Uri::getQueryParams() - success - an absent query returns null
+--FILE--
+getQueryParams());
+
+?>
+--EXPECT--
+NULL
diff --git a/ext/uri/tests/rfc3986/modification/query_params_success_basic.phpt b/ext/uri/tests/rfc3986/modification/query_params_success_basic.phpt
new file mode 100644
index 000000000000..bbe9c0a78b52
--- /dev/null
+++ b/ext/uri/tests/rfc3986/modification/query_params_success_basic.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Test Uri\Rfc3986\Uri::withQueryParams() - success - replace a non-empty query
+--FILE--
+withQueryParams($params);
+
+var_dump($uri1->getRawQuery());
+var_dump($uri2->getRawQuery());
+var_dump($uri2->toRawString());
+var_dump($uri2->getQuery());
+var_dump($uri2->toString());
+
+?>
+--EXPECT--
+string(5) "old=1"
+string(15) "foo=bar&foo=baz"
+string(35) "https://example.com?foo=bar&foo=baz"
+string(15) "foo=bar&foo=baz"
+string(35) "https://example.com?foo=bar&foo=baz"
diff --git a/ext/uri/tests/rfc3986/modification/query_params_success_empty.phpt b/ext/uri/tests/rfc3986/modification/query_params_success_empty.phpt
new file mode 100644
index 000000000000..72eaec2cb1e8
--- /dev/null
+++ b/ext/uri/tests/rfc3986/modification/query_params_success_empty.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Test Uri\Rfc3986\Uri::withQueryParams() - success - empty list with an absent query
+--FILE--
+withQueryParams($params);
+
+var_dump($uri1->getRawQuery());
+var_dump($uri2->getRawQuery());
+var_dump($uri2->toRawString());
+var_dump($uri2->getQuery());
+var_dump($uri2->toString());
+
+?>
+--EXPECT--
+NULL
+string(0) ""
+string(20) "https://example.com?"
+string(0) ""
+string(20) "https://example.com?"
diff --git a/ext/uri/tests/rfc3986/modification/query_params_success_null.phpt b/ext/uri/tests/rfc3986/modification/query_params_success_null.phpt
new file mode 100644
index 000000000000..231971e89a4f
--- /dev/null
+++ b/ext/uri/tests/rfc3986/modification/query_params_success_null.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Test Uri\Rfc3986\Uri::withQueryParams() - success - null removes a non-empty query
+--FILE--
+withQueryParams(null);
+
+var_dump($uri1->getRawQuery());
+var_dump($uri2->getRawQuery());
+var_dump($uri2->toRawString());
+var_dump($uri2->getQuery());
+var_dump($uri2->toString());
+
+?>
+--EXPECT--
+string(7) "foo=bar"
+NULL
+string(19) "https://example.com"
+NULL
+string(19) "https://example.com"
diff --git a/ext/uri/tests/whatwg/getters/query_params_success_empty.phpt b/ext/uri/tests/whatwg/getters/query_params_success_empty.phpt
new file mode 100644
index 000000000000..17302c09e59a
--- /dev/null
+++ b/ext/uri/tests/whatwg/getters/query_params_success_empty.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Test Uri\WhatWg\Url::getQueryParams() - success - a present empty query returns an empty instance
+--FILE--
+getQueryParams();
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(0) {
+}
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/ext/uri/tests/whatwg/getters/query_params_success_leading_question_mark.phpt b/ext/uri/tests/whatwg/getters/query_params_success_leading_question_mark.phpt
new file mode 100644
index 000000000000..2c8a0f1b73d8
--- /dev/null
+++ b/ext/uri/tests/whatwg/getters/query_params_success_leading_question_mark.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test Uri\WhatWg\Url::getQueryParams() - success - a query component keeps its leading question mark
+--FILE--
+getQueryParams();
+
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(4) "?foo"
+ [1]=>
+ string(3) "bar"
+ }
+}
+string(10) "%3Ffoo=bar"
+string(8) "?foo=bar"
+string(10) "%3Ffoo=bar"
diff --git a/ext/uri/tests/whatwg/getters/query_params_success_new_instance.phpt b/ext/uri/tests/whatwg/getters/query_params_success_new_instance.phpt
new file mode 100644
index 000000000000..2eb54626438c
--- /dev/null
+++ b/ext/uri/tests/whatwg/getters/query_params_success_new_instance.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test Uri\WhatWg\Url::getQueryParams() - success - each call creates an independent instance
+--FILE--
+getQueryParams();
+$params = $uri->getQueryParams();
+var_dump($first === $params);
+
+$first = $first->append("y", "2");
+var_dump($params->toList());
+var_dump($params->toRfc1866String());
+var_dump($params->toRfc3986String());
+var_dump($params->toWhatWgUrlString());
+var_dump($uri->getQuery());
+
+?>
+--EXPECT--
+bool(false)
+array(1) {
+ [0]=>
+ array(2) {
+ [0]=>
+ string(1) "x"
+ [1]=>
+ string(1) "1"
+ }
+}
+string(3) "x=1"
+string(3) "x=1"
+string(3) "x=1"
+string(3) "x=1"
diff --git a/ext/uri/tests/whatwg/getters/query_params_success_null.phpt b/ext/uri/tests/whatwg/getters/query_params_success_null.phpt
new file mode 100644
index 000000000000..f939f4f0c8f1
--- /dev/null
+++ b/ext/uri/tests/whatwg/getters/query_params_success_null.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test Uri\WhatWg\Url::getQueryParams() - success - an absent query returns null
+--FILE--
+getQueryParams());
+
+?>
+--EXPECT--
+NULL
diff --git a/ext/uri/tests/whatwg/modification/query_params_success_basic.phpt b/ext/uri/tests/whatwg/modification/query_params_success_basic.phpt
new file mode 100644
index 000000000000..74b6fdfdf0f9
--- /dev/null
+++ b/ext/uri/tests/whatwg/modification/query_params_success_basic.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\WhatWg\Url::withQueryParams() - success - replace a non-empty query
+--FILE--
+withQueryParams($params);
+
+var_dump($url1->getQuery());
+var_dump($url2->getQuery());
+var_dump($url2->toAsciiString());
+
+?>
+--EXPECT--
+string(5) "old=1"
+string(15) "foo=bar&foo=baz"
+string(36) "https://example.com/?foo=bar&foo=baz"
diff --git a/ext/uri/tests/whatwg/modification/query_params_success_empty.phpt b/ext/uri/tests/whatwg/modification/query_params_success_empty.phpt
new file mode 100644
index 000000000000..dc85f119407f
--- /dev/null
+++ b/ext/uri/tests/whatwg/modification/query_params_success_empty.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Test Uri\WhatWg\Url::withQueryParams() - success - empty list with an absent query
+--FILE--
+withQueryParams($params);
+
+var_dump($url1->getQuery());
+var_dump($url2->getQuery());
+var_dump($url2->toAsciiString());
+
+?>
+--EXPECT--
+NULL
+NULL
+string(20) "https://example.com/"
diff --git a/ext/uri/tests/whatwg/modification/query_params_success_null.phpt b/ext/uri/tests/whatwg/modification/query_params_success_null.phpt
new file mode 100644
index 000000000000..8a2270c47e19
--- /dev/null
+++ b/ext/uri/tests/whatwg/modification/query_params_success_null.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test Uri\WhatWg\Url::withQueryParams() - success - null removes a non-empty query
+--FILE--
+withQueryParams(null);
+
+var_dump($url1->getQuery());
+var_dump($url2->getQuery());
+var_dump($url2->toAsciiString());
+
+?>
+--EXPECT--
+string(7) "foo=bar"
+NULL
+string(20) "https://example.com/"
diff --git a/ext/uri/uri_parser_rfc3986.c b/ext/uri/uri_parser_rfc3986.c
index f9e913063903..569b60929b6b 100644
--- a/ext/uri/uri_parser_rfc3986.c
+++ b/ext/uri/uri_parser_rfc3986.c
@@ -20,6 +20,7 @@
#include "Zend/zend_exceptions.h"
#include
+#include "uriparser/src/UriSets.h"
struct php_uri_parser_rfc3986_uris {
UriUriA uri;
@@ -796,6 +797,117 @@ ZEND_ATTRIBUTE_NONNULL static zend_string *php_uri_parser_rfc3986_to_string(void
return uri_string;
}
+zend_string *php_uri_parser_rfc3986_query_component_percent_decode(const char *str, const size_t str_length, const bool plus_to_space)
+{
+ if (UNEXPECTED(str == NULL)) {
+ return NULL;
+ }
+
+ if (UNEXPECTED(str_length == 0)) {
+ return zend_empty_string;
+ }
+
+ const bool needs_decoding = memchr(str, '%', str_length) != NULL
+ || (plus_to_space && memchr(str, '+', str_length) != NULL);
+ if (EXPECTED(!needs_decoding)) {
+ return zend_string_init(str, str_length, false);
+ }
+
+ zend_string *result = zend_string_alloc(str_length, false);
+
+ memcpy(ZSTR_VAL(result), str, str_length);
+ ZSTR_VAL(result)[str_length] = '\0';
+
+ const char *end = uriUnescapeInPlaceEx2A(
+ ZSTR_VAL(result), ZSTR_VAL(result) + str_length, plus_to_space, URI_BR_DONT_TOUCH);
+
+ ZSTR_LEN(result) = (size_t)(end - ZSTR_VAL(result));
+
+ return result;
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_rfc3986_query_component_percent_encode(const char *str, const size_t str_length, const bool space_to_plus)
+{
+ /* An RFC 1866 line break can expand to "%0D%0A". */
+ zend_string *result = zend_string_safe_alloc(space_to_plus ? 6 : 3, str_length, 0, false);
+
+ char *end;
+
+ if (space_to_plus) {
+ end = uriEscapeQueryRfc1866ExA(str, str + str_length, ZSTR_VAL(result));
+ } else {
+ end = uriEscapeQueryRfc3986ExA(str, str + str_length, ZSTR_VAL(result));
+
+ /* The generic query encoder leaves parameter delimiters unescaped. */
+ size_t delimiter_count = 0;
+ for (const char *p = ZSTR_VAL(result); p < end; p++) {
+ delimiter_count += *p == '&' || *p == '=';
+ }
+ if (delimiter_count != 0) {
+ /* Expand backwards within the already allocated worst-case buffer. */
+ char *read = end;
+ end += 2 * delimiter_count;
+ char *write = end;
+ *write = '\0';
+ while (read > ZSTR_VAL(result)) {
+ const char c = *--read;
+ if (c == '&' || c == '=') {
+ write -= 3;
+ memcpy(write, c == '&' ? "%26" : "%3D", 3);
+ } else {
+ *--write = c;
+ }
+ }
+ }
+ }
+
+ ZSTR_LEN(result) = (size_t)(end - ZSTR_VAL(result));
+
+ return result;
+}
+
+ZEND_ATTRIBUTE_NONNULL static void php_uri_parser_rfc3986_query_component_append_to_string(
+ const zend_string *component, const bool space_to_plus, smart_str *buf
+) {
+ const bool needs_percent_encoding = true; // TODO
+ if (UNEXPECTED(needs_percent_encoding)) {
+ zend_string *encoded = php_uri_parser_rfc3986_query_component_percent_encode(ZSTR_VAL(component), ZSTR_LEN(component), space_to_plus);
+ smart_str_append(buf, encoded);
+ zend_string_release(encoded);
+ } else {
+ smart_str_appendl(buf, ZSTR_VAL(component), ZSTR_LEN(component));
+ }
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_rfc3986_query_params_to_string(
+ const php_uri_query_params_object *query_params_object, const bool space_to_plus
+) {
+ smart_str buf = {0};
+ bool is_first = true;
+
+ ZEND_HASH_FOREACH_PTR(&query_params_object->entry_list, php_uri_query_param_list_entry *entry) {
+ const zend_string *name = entry->key;
+ const zend_string *value = entry->value;
+
+ if (name == NULL) {
+ continue;
+ }
+
+ if (!is_first) {
+ smart_str_appendc(&buf, '&');
+ }
+ is_first = false;
+
+ php_uri_parser_rfc3986_query_component_append_to_string(name, space_to_plus, &buf);
+ if (value != NULL) {
+ smart_str_appendc(&buf, '=');
+ php_uri_parser_rfc3986_query_component_append_to_string(value, space_to_plus, &buf);
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ return buf.s != NULL ? smart_str_extract(&buf) : ZSTR_EMPTY_ALLOC();
+}
+
static void php_uri_parser_rfc3986_destroy(void *uri)
{
php_uri_parser_rfc3986_uris *uriparser_uris = uri;
@@ -896,11 +1008,57 @@ ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_path_validate(const ze
return php_uri_parser_rfc3986_validate_component_result(well_formed, "path");
}
+ZEND_ATTRIBUTE_NONNULL bool php_uri_parser_rfc1866_query_is_well_formed(const char *query, const size_t query_length)
+{
+ const char *first = query;
+ const char *after_last = first + query_length;
+
+ while (first < after_last) {
+ switch (first[0]) {
+ case URI_SET_UNRESERVED():
+ case '+':
+ case '&':
+ case '=':
+ break;
+
+ /* pct-encoded */
+ case '%':
+ if (after_last - first < 3) {
+ return false;
+ }
+ switch (first[1]) {
+ case URI_SET_HEXDIG():
+ break;
+ default:
+ return false;
+ }
+ switch (first[2]) {
+ case URI_SET_HEXDIG():
+ break;
+ default:
+ return false;
+ }
+ first += 2;
+ break;
+
+ default:
+ return false;
+ }
+
+ first++;
+ }
+
+ return true;
+}
+
+ZEND_ATTRIBUTE_NONNULL bool php_uri_parser_rfc3986_query_is_well_formed(const char *query, const size_t query_length)
+{
+ return uriIsWellFormedQueryA(query, query + query_length) == URI_TRUE;
+}
+
ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_query_validate(const zend_string *query)
{
- const char *p = ZSTR_VAL(query);
- const size_t len = ZSTR_LEN(query);
- const bool well_formed = uriIsWellFormedQueryA(p, p + len);
+ const bool well_formed = php_uri_parser_rfc3986_query_is_well_formed(ZSTR_VAL(query), ZSTR_LEN(query));
return php_uri_parser_rfc3986_validate_component_result(well_formed, "query");
}
diff --git a/ext/uri/uri_parser_rfc3986.h b/ext/uri/uri_parser_rfc3986.h
index 838b86771257..3b490e140553 100644
--- a/ext/uri/uri_parser_rfc3986.h
+++ b/ext/uri/uri_parser_rfc3986.h
@@ -34,6 +34,8 @@ ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_userinfo_validate(cons
ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_host_validate(const zend_string *host);
ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_port_validate(zend_long port);
ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_path_validate(const zend_string *path);
+ZEND_ATTRIBUTE_NONNULL bool php_uri_parser_rfc1866_query_is_well_formed(const char *query, size_t query_length);
+ZEND_ATTRIBUTE_NONNULL bool php_uri_parser_rfc3986_query_is_well_formed(const char *query, size_t query_length);
ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_query_validate(const zend_string *query);
ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_rfc3986_fragment_validate(const zend_string *fragment);
@@ -43,4 +45,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(2,3,4,5,6,7,8) php_uri_parser_rfc3986_uris *php_uri_
const zval *path, const zval *query, const zval *fragment
);
+zend_string *php_uri_parser_rfc3986_query_component_percent_decode(const char *str, size_t str_length, bool plus_to_space);
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_rfc3986_query_params_to_string(const php_uri_query_params_object *query_params_object, bool space_to_plus);
+
#endif
diff --git a/ext/uri/uri_parser_whatwg.c b/ext/uri/uri_parser_whatwg.c
index 2a4457e3dc9c..51c63dcbc2f3 100644
--- a/ext/uri/uri_parser_whatwg.c
+++ b/ext/uri/uri_parser_whatwg.c
@@ -18,6 +18,7 @@
#include "Zend/zend_enum.h"
#include "Zend/zend_smart_str.h"
#include "Zend/zend_exceptions.h"
+#include "lexbor/encoding/decode.h"
#ifdef HAVE_ARPA_INET_H
#include
#endif
@@ -588,6 +589,113 @@ static zend_result php_uri_parser_whatwg_fragment_write(void *uri, const zval *v
return SUCCESS;
}
+ZEND_ATTRIBUTE_NONNULL static void php_uri_parser_whatwg_query_component_repair_utf8(
+ const char *str, const size_t str_length, smart_str *repaired_utf8
+)
+{
+ const lxb_char_t *p = (const lxb_char_t *) str;
+ const lxb_char_t *end = p + str_length;
+ const lxb_char_t *start = p;
+ lxb_encoding_decode_t decoder = {0};
+
+ /* UTF-8 decode without BOM: preserve valid bytes, including an initial BOM. */
+ while (p < end) {
+ const lxb_char_t *previous = p;
+ const lxb_codepoint_t codepoint = lxb_encoding_decode_utf_8_single(&decoder, &p, end);
+ if (codepoint == LXB_ENCODING_DECODE_ERROR || codepoint == LXB_ENCODING_DECODE_CONTINUE) {
+ smart_str_appendl(repaired_utf8, (const char *) start, previous - start);
+ smart_str_appendl(repaired_utf8, (const char *) LXB_ENCODING_REPLACEMENT_BYTES, LXB_ENCODING_REPLACEMENT_SIZE);
+ start = p;
+ }
+ }
+
+ if (repaired_utf8->s != NULL) {
+ smart_str_appendl(repaired_utf8, (const char *) start, end - start);
+ }
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_whatwg_query_component_percent_decode(const char *str, const size_t str_length)
+{
+ lexbor_str_t result = {0};
+
+ const lxb_status_t status = lxb_url_percent_decode_plus(
+ (const lxb_char_t *) str, (const lxb_char_t *) (str + str_length),
+ &result, &lexbor_mraw
+ );
+
+ if (status != LXB_STATUS_OK) {
+ lexbor_str_destroy(&result, &lexbor_mraw, false);
+ return NULL;
+ }
+
+ smart_str repaired_utf8 = {0};
+ php_uri_parser_whatwg_query_component_repair_utf8((const char *) result.data, result.length, &repaired_utf8);
+ zend_string *decoded = repaired_utf8.s != NULL
+ ? smart_str_extract(&repaired_utf8)
+ : zend_string_init((const char *) result.data, result.length, false);
+ lexbor_str_destroy(&result, &lexbor_mraw, false);
+ return decoded;
+}
+
+ZEND_ATTRIBUTE_NONNULL static zend_string *php_uri_parser_whatwg_query_component_percent_encode(const zend_string *component)
+{
+ smart_str repaired_utf8 = {0};
+ php_uri_parser_whatwg_query_component_repair_utf8(ZSTR_VAL(component), ZSTR_LEN(component), &repaired_utf8);
+
+ if (repaired_utf8.s == NULL) {
+ return php_uri_parser_whatwg_form_query_percent_encode(ZSTR_VAL(component), ZSTR_LEN(component));
+ }
+
+ zend_string *result = php_uri_parser_whatwg_form_query_percent_encode(ZSTR_VAL(repaired_utf8.s), ZSTR_LEN(repaired_utf8.s));
+ smart_str_free(&repaired_utf8);
+ return result;
+}
+
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_whatwg_query_params_to_string(const php_uri_query_params_object *object)
+{
+ smart_str buf = {0};
+ bool is_first = true;
+
+ ZEND_HASH_FOREACH_PTR(&object->entry_list, php_uri_query_param_list_entry *entry) {
+ if (entry->key == NULL) {
+ continue;
+ }
+
+ /* Omit empty fields preserved by the RFC-based parsers. */
+ if (ZSTR_LEN(entry->key) == 0 && entry->value == NULL) {
+ continue;
+ }
+
+ zend_string *name = php_uri_parser_whatwg_query_component_percent_encode(entry->key);
+ if (UNEXPECTED(name == NULL)) {
+ smart_str_free(&buf);
+ return NULL;
+ }
+
+ if (is_first) {
+ is_first = false;
+ } else {
+ smart_str_appendc(&buf, '&');
+ }
+
+ smart_str_append(&buf, name);
+ zend_string_release(name);
+
+ if (entry->value != NULL) {
+ zend_string *value = php_uri_parser_whatwg_query_component_percent_encode(entry->value);
+ if (UNEXPECTED(value == NULL)) {
+ smart_str_free(&buf);
+ return NULL;
+ }
+ smart_str_appendc(&buf, '=');
+ smart_str_append(&buf, value);
+ zend_string_release(value);
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ return buf.s != NULL ? smart_str_extract(&buf) : ZSTR_EMPTY_ALLOC();
+}
+
PHP_RINIT_FUNCTION(uri_parser_whatwg)
{
lxb_status_t status = lexbor_mraw_init(&lexbor_mraw, lexbor_mraw_byte_size);
diff --git a/ext/uri/uri_parser_whatwg.h b/ext/uri/uri_parser_whatwg.h
index 360e8a2cd567..ae457cbcbf07 100644
--- a/ext/uri/uri_parser_whatwg.h
+++ b/ext/uri/uri_parser_whatwg.h
@@ -46,6 +46,9 @@ ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_whatwg_special_query_percent_
ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_whatwg_form_query_percent_encode(const char *str, size_t str_length);
ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_whatwg_fragment_percent_encode(const char *str, size_t str_length);
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_whatwg_query_component_percent_decode(const char *str, size_t str_length);
+ZEND_ATTRIBUTE_NONNULL zend_string *php_uri_parser_whatwg_query_params_to_string(const php_uri_query_params_object *object);
+
PHP_RINIT_FUNCTION(uri_parser_whatwg);
ZEND_MODULE_POST_ZEND_DEACTIVATE_D(uri_parser_whatwg);
diff --git a/ext/uri/uriparser/include/uriparser/Uri.h b/ext/uri/uriparser/include/uriparser/Uri.h
index e05ebfb23842..6be837ecd222 100644
--- a/ext/uri/uriparser/include/uriparser/Uri.h
+++ b/ext/uri/uriparser/include/uriparser/Uri.h
@@ -441,6 +441,116 @@ URI_PUBLIC URI_CHAR * URI_FUNC(EscapeEx)(const URI_CHAR * inFirst,
URI_PUBLIC URI_CHAR * URI_FUNC(Escape)(const URI_CHAR * in, URI_CHAR * out,
UriBool spaceToPlus, UriBool normalizeBreaks);
+/**
+ * Percent-encodes the input string according to the
+ * application/x-www-form-urlencoded format defined in RFC 1866, converting
+ * spaces to '+', normalizing line breaks to CR-LF pairs, and encoding all
+ * characters outside the unreserved set, then writes the result to the
+ * output string.
+ *
+ * NOTE: Be sure to allocate 6 times the space of the input buffer for
+ * the output buffer (since e.g. "\x0d" becomes "%0D%0A" in that case).
+ *
+ * NOTE: The implementation treats (both char and) wchar_t units
+ * as code point integers, which works well for code points U+0001 to U+00ff
+ * in host-native endianness but nothing more;
+ * in particular, using uriEscapeQueryRfc1866ExW with arbitrary Unicode input will
+ * not produce healthy results.
+ * Passing UTF-8 input to uriEscapeQueryRfc1866ExA may be useful in some scenarios.
+ * Keep in mind that uriparser is about %URI (RFC 3986) not %IRI (RFC 3987).
+ *
+ * @param inFirst IN: Pointer to first character of the input text
+ * @param inAfterLast IN: Pointer after the last character of the input text
+ * @param out OUT: Encoded text destination
+ * @return Position of terminator in output string
+ *
+ * @see uriEscapeQueryRfc1866A
+ * @see uriUnescapeInPlaceExA
+ * @since 1.0.3
+ */
+URI_PUBLIC URI_CHAR * URI_FUNC(EscapeQueryRfc1866Ex)(
+ const URI_CHAR * inFirst, const URI_CHAR * inAfterLast, URI_CHAR * out);
+
+/**
+ * Percent-encodes the input string according to the
+ * application/x-www-form-urlencoded format defined in RFC 1866, converting
+ * spaces to '+', normalizing line breaks to CR-LF pairs, and encoding all
+ * characters outside the unreserved set, then writes the result to the
+ * output string.
+ *
+ * NOTE: Be sure to allocate 6 times the space of the input buffer for
+ * the output buffer (since e.g. "\x0d" becomes "%0D%0A" in that case).
+ *
+ * NOTE: The implementation treats (both char and) wchar_t units
+ * as code point integers, which works well for code points U+0001 to U+00ff
+ * in host-native endianness but nothing more;
+ * in particular, using uriEscapeQueryRfc1866W with arbitrary Unicode input will
+ * not produce healthy results.
+ * Passing UTF-8 input to uriEscapeQueryRfc1866A may be useful in some scenarios.
+ * Keep in mind that uriparser is about %URI (RFC 3986) not %IRI (RFC 3987).
+ *
+ * @param in IN: Text source
+ * @param out OUT: Encoded text destination
+ * @return Position of terminator in output string
+ *
+ * @see uriEscapeQueryRfc1866ExA
+ * @see uriUnescapeInPlaceA
+ * @since 1.0.3
+ */
+URI_PUBLIC URI_CHAR * URI_FUNC(EscapeQueryRfc1866)(const URI_CHAR * in, URI_CHAR * out);
+
+/**
+ * Percent-encodes the input string according to RFC 3986 (i.e. encoding all characters
+ * outside "pchar", "/" and "?"), then writes the result to the output string.
+ *
+ * NOTE: Be sure to allocate 3 times the space of the input buffer for
+ * the output buffer.
+ *
+ * NOTE: The implementation treats (both char and) wchar_t units
+ * as code point integers, which works well for code points U+0001 to U+00ff
+ * in host-native endianness but nothing more;
+ * in particular, using uriEscapeQueryRfc3986ExW with arbitrary Unicode input will
+ * not produce healthy results.
+ * Passing UTF-8 input to uriEscapeQueryRfc3986ExA may be useful in some scenarios.
+ * Keep in mind that uriparser is about %URI (RFC 3986) not %IRI (RFC 3987).
+ *
+ * @param inFirst IN: Pointer to first character of the input text
+ * @param inAfterLast IN: Pointer after the last character of the input text
+ * @param out OUT: Encoded text destination
+ * @return Position of terminator in output string
+ *
+ * @see uriEscapeQueryRfc3986A
+ * @see uriUnescapeInPlaceExA
+ * @since 1.0.3
+ */
+URI_PUBLIC URI_CHAR * URI_FUNC(EscapeQueryRfc3986Ex)(
+ const URI_CHAR * inFirst, const URI_CHAR * inAfterLast, URI_CHAR * out);
+
+/**
+ * Percent-encodes the input string according to RFC 3986 (i.e. encoding all characters
+ * outside "pchar", "/" and "?"), then writes the result to the output string.
+ *
+ * NOTE: Be sure to allocate 3 times the space of the input buffer for
+ * the output buffer.
+ *
+ * NOTE: The implementation treats (both char and) wchar_t units
+ * as code point integers, which works well for code points U+0001 to U+00ff
+ * in host-native endianness but nothing more;
+ * in particular, using uriEscapeQueryRfc3986W with arbitrary Unicode input will
+ * not produce healthy results.
+ * Passing UTF-8 input to uriEscapeQueryRfc3986A may be useful in some scenarios.
+ * Keep in mind that uriparser is about %URI (RFC 3986) not %IRI (RFC 3987).
+ *
+ * @param in IN: Text source
+ * @param out OUT: Encoded text destination
+ * @return Position of terminator in output string
+ *
+ * @see uriEscapeQueryRfc3986ExA
+ * @see uriUnescapeInPlaceA
+ * @since 1.0.3
+ */
+URI_PUBLIC URI_CHAR * URI_FUNC(EscapeQueryRfc3986)(const URI_CHAR * in, URI_CHAR * out);
+
/**
* Unescapes percent-encoded groups in a given string.
* E.g. "%20" will become " ". Unescaping is done in place.
@@ -461,6 +571,26 @@ URI_PUBLIC URI_CHAR * URI_FUNC(Escape)(const URI_CHAR * in, URI_CHAR * out,
URI_PUBLIC const URI_CHAR * URI_FUNC(UnescapeInPlaceEx)(
URI_CHAR * inout, UriBool plusToSpace, UriBreakConversion breakConversion);
+/**
+ * Unescapes percent-encoded groups in place, optionally using an explicit
+ * input end pointer. If inAfterLast is not NULL, embedded zero characters
+ * are preserved and decoding continues up to inAfterLast.
+ * The buffer must have room for a terminating zero at inAfterLast, which
+ * is written at the end of the decoded output. Use the returned pointer
+ * to determine the output length, including any embedded zero characters.
+ *
+ * @param inout INOUT: Text to unescape/decode
+ * @param inAfterLast IN: Pointer after the last input character, or NULL for zero-terminated input
+ * @param plusToSpace IN: Whether to convert '+' to ' ' or not
+ * @param breakConversion IN: Line break conversion mode
+ * @return Pointer to the terminating zero, or NULL if inout is NULL
+ *
+ * @see uriUnescapeInPlaceExA
+ */
+URI_PUBLIC const URI_CHAR *
+ URI_FUNC(UnescapeInPlaceEx2)(URI_CHAR * inout, const URI_CHAR * inAfterLast,
+ UriBool plusToSpace, UriBreakConversion breakConversion);
+
/**
* Unescapes percent-encoded groups in a given string.
* E.g. "%20" will become " ". Unescaping is done in place.
diff --git a/ext/uri/uriparser/src/UriEscape.c b/ext/uri/uriparser/src/UriEscape.c
index a3b9e848a8f4..0c916d6f2b62 100644
--- a/ext/uri/uriparser/src/UriEscape.c
+++ b/ext/uri/uriparser/src/UriEscape.c
@@ -65,13 +65,9 @@
# include "UriSets.h"
# endif
-URI_CHAR * URI_FUNC(Escape)(const URI_CHAR * in, URI_CHAR * out, UriBool spaceToPlus,
- UriBool normalizeBreaks) {
- return URI_FUNC(EscapeEx)(in, NULL, out, spaceToPlus, normalizeBreaks);
-}
-
-URI_CHAR * URI_FUNC(EscapeEx)(const URI_CHAR * inFirst, const URI_CHAR * inAfterLast,
- URI_CHAR * out, UriBool spaceToPlus, UriBool normalizeBreaks) {
+URI_CHAR * URI_FUNC(EscapeQueryEngine)(const URI_CHAR * inFirst,
+ const URI_CHAR * inAfterLast, URI_CHAR * out, UriBool spaceToPlus,
+ UriBool encodeReserved, UriBool normalizeBreaks) {
const URI_CHAR * read = inFirst;
URI_CHAR * write = out;
UriBool prevWasCr = URI_FALSE;
@@ -85,16 +81,12 @@ URI_CHAR * URI_FUNC(EscapeEx)(const URI_CHAR * inFirst, const URI_CHAR * inAfter
}
for (;;) {
- if ((inAfterLast != NULL) && (read >= inAfterLast)) {
+ if ((inAfterLast != NULL) ? (read >= inAfterLast) : (read[0] == _UT('\0'))) {
write[0] = _UT('\0');
return write;
}
switch (read[0]) {
- case _UT('\0'):
- write[0] = _UT('\0');
- return write;
-
case _UT(' '):
if (spaceToPlus) {
write[0] = _UT('+');
@@ -154,6 +146,26 @@ URI_CHAR * URI_FUNC(EscapeEx)(const URI_CHAR * inFirst, const URI_CHAR * inAfter
prevWasCr = URI_TRUE;
break;
+ case URI_SET_SUB_DELIMS(_UT):
+ /* intentional fallback */
+ case _UT(':'):
+ /* intentional fallback */
+ case _UT('@'):
+ /* intentional fallback */
+ case _UT('/'):
+ /* intentional fallback */
+ case _UT('?'):
+ if (!encodeReserved) {
+ /* Copy unmodified */
+ write[0] = read[0];
+ write++;
+
+ prevWasCr = URI_FALSE;
+ break;
+ }
+
+ /* intentional fallback */
+
default:
/* Percent encode */
{
@@ -174,12 +186,51 @@ URI_CHAR * URI_FUNC(EscapeEx)(const URI_CHAR * inFirst, const URI_CHAR * inAfter
}
}
+URI_CHAR * URI_FUNC(Escape)(const URI_CHAR * in, URI_CHAR * out, UriBool spaceToPlus,
+ UriBool normalizeBreaks) {
+ return URI_FUNC(EscapeEx)(in, NULL, out, spaceToPlus, normalizeBreaks);
+}
+
+URI_CHAR * URI_FUNC(EscapeEx)(const URI_CHAR * inFirst, const URI_CHAR * inAfterLast,
+ URI_CHAR * out, UriBool spaceToPlus, UriBool normalizeBreaks) {
+ return URI_FUNC(EscapeQueryEngine)(
+ inFirst, inAfterLast, out, spaceToPlus, URI_TRUE, normalizeBreaks);
+}
+
+URI_CHAR * URI_FUNC(EscapeQueryRfc1866)(const URI_CHAR * in, URI_CHAR * out) {
+ return URI_FUNC(EscapeQueryRfc1866Ex)(in, NULL, out);
+}
+
+URI_CHAR * URI_FUNC(EscapeQueryRfc1866Ex)(
+ const URI_CHAR * inFirst, const URI_CHAR * inAfterLast, URI_CHAR * out) {
+ return URI_FUNC(EscapeQueryEngine)(inFirst, inAfterLast, out,
+ /*spaceToPlus*/ URI_TRUE, /*encodeReserved*/ URI_TRUE,
+ /*normalizeBreaks*/ URI_TRUE);
+}
+
+URI_CHAR * URI_FUNC(EscapeQueryRfc3986)(const URI_CHAR * in, URI_CHAR * out) {
+ return URI_FUNC(EscapeQueryRfc3986Ex)(in, NULL, out);
+}
+
+URI_CHAR * URI_FUNC(EscapeQueryRfc3986Ex)(
+ const URI_CHAR * inFirst, const URI_CHAR * inAfterLast, URI_CHAR * out) {
+ return URI_FUNC(EscapeQueryEngine)(inFirst, inAfterLast, out,
+ /*spaceToPlus*/ URI_FALSE, /*encodeReserved*/ URI_FALSE,
+ /*normalizeBreaks*/ URI_FALSE);
+}
+
const URI_CHAR * URI_FUNC(UnescapeInPlace)(URI_CHAR * inout) {
return URI_FUNC(UnescapeInPlaceEx)(inout, URI_FALSE, URI_BR_DONT_TOUCH);
}
const URI_CHAR * URI_FUNC(UnescapeInPlaceEx)(
URI_CHAR * inout, UriBool plusToSpace, UriBreakConversion breakConversion) {
+ return URI_FUNC(UnescapeInPlaceEx2)(inout, NULL, plusToSpace, breakConversion);
+}
+
+const URI_CHAR * URI_FUNC(UnescapeInPlaceEx2)(URI_CHAR * inout,
+ const URI_CHAR * inAfterLast, UriBool plusToSpace,
+ UriBreakConversion breakConversion) {
URI_CHAR * read = inout;
URI_CHAR * write = inout;
UriBool prevWasCr = URI_FALSE;
@@ -189,14 +240,21 @@ const URI_CHAR * URI_FUNC(UnescapeInPlaceEx)(
}
for (;;) {
- switch (read[0]) {
- case _UT('\0'):
- if (read > write) {
- write[0] = _UT('\0');
- }
+ if ((inAfterLast != NULL) ? (read >= inAfterLast) : (read[0] == _UT('\0'))) {
+ write[0] = _UT('\0');
return write;
+ }
+ switch (read[0]) {
case _UT('%'):
+ if ((inAfterLast != NULL) && (inAfterLast - read < 3)) {
+ /* Preserve an incomplete percent group without reading past the input. */
+ write[0] = read[0];
+ read++;
+ write++;
+ prevWasCr = URI_FALSE;
+ break;
+ }
switch (read[1]) {
case URI_SET_HEXDIG(_UT):
switch (read[2]) {