Skip to content

Commit 0ad50d0

Browse files
committed
Changes based on discussion
1 parent 4d928c5 commit 0ad50d0

40 files changed

+929
-769
lines changed

ext/dom/lexbor/lexbor/url/url.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C" {
2323

2424

2525
typedef enum {
26-
LXB_URL_ERROR_TYPE_DOMAIN_TO_ASCII = 0x00,
26+
LXB_URL_ERROR_TYPE_DOMAIN_TO_ASCII = 0x00,
2727
LXB_URL_ERROR_TYPE_DOMAIN_TO_UNICODE,
2828
LXB_URL_ERROR_TYPE_DOMAIN_INVALID_CODE_POINT,
2929
LXB_URL_ERROR_TYPE_HOST_INVALID_CODE_POINT,

ext/filter/logical_filters.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
604604
zval *option_val;
605605
zend_string *parser_name;
606606
int parser_name_set;
607-
FETCH_STR_OPTION(parser_name, "parser");
607+
FETCH_STR_OPTION(parser_name, "uri_parser_class");
608608

609609
uri_handler_t *uri_handler = php_uri_get_handler(parser_name_set ? parser_name : NULL);
610610
if (uri_handler == NULL) {

ext/filter/tests/062.phpt

+12-12
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@ function validateUrls(string $parserName)
5353
];
5454

5555
foreach ($values as $value) {
56-
var_dump(filter_var($value, FILTER_VALIDATE_URL, ["parser" => $parserName]));
56+
var_dump(filter_var($value, FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName]));
5757
}
5858

59-
var_dump(filter_var("qwe", FILTER_VALIDATE_URL, ["parser" => $parserName]));
60-
var_dump(filter_var("http://qwe", FILTER_VALIDATE_URL, ["parser" => $parserName]));
61-
var_dump(filter_var("http://", FILTER_VALIDATE_URL, ["parser" => $parserName]));
62-
var_dump(filter_var("/tmp/test", FILTER_VALIDATE_URL, ["parser" => $parserName]));
63-
var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["parser" => $parserName]));
64-
var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED]));
65-
var_dump(filter_var("http://www.example.com/path/at/the/server/", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED]));
66-
var_dump(filter_var("http://www.example.com/index.html", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED]));
67-
var_dump(filter_var("http://www.example.com/index.php?a=b&c=d", FILTER_VALIDATE_URL, ["parser" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED]));
59+
var_dump(filter_var("qwe", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName]));
60+
var_dump(filter_var("http://qwe", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName]));
61+
var_dump(filter_var("http://", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName]));
62+
var_dump(filter_var("/tmp/test", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName]));
63+
var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName]));
64+
var_dump(filter_var("http://www.example.com", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED]));
65+
var_dump(filter_var("http://www.example.com/path/at/the/server/", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_PATH_REQUIRED]));
66+
var_dump(filter_var("http://www.example.com/index.html", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED]));
67+
var_dump(filter_var("http://www.example.com/index.php?a=b&c=d", FILTER_VALIDATE_URL, ["uri_parser_class" => $parserName, "flags" => FILTER_FLAG_QUERY_REQUIRED]));
6868
}
6969

7070
echo "RFC3986:\n";
71-
validateUrls(Uri\URI_PARSER_RFC3986);
71+
validateUrls(Uri\Rfc3986Uri::class);
7272

7373
echo "\nWHATWG:\n";
74-
validateUrls(Uri\URI_PARSER_WHATWG);
74+
validateUrls(Uri\WhatWgUri::class);
7575

7676
echo "Done\n";
7777
?>

ext/soap/php_http.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ int make_http_soap_request(zval *this_ptr,
341341
zend_string *location,
342342
char *soapaction,
343343
int soap_version,
344-
const zend_string *uri_parser_name,
344+
const zend_string *uri_parser_class,
345345
zval *return_value)
346346
{
347347
zend_string *request;
@@ -435,7 +435,7 @@ int make_http_soap_request(zval *this_ptr,
435435
}
436436

437437
if (location != NULL && ZSTR_VAL(location)[0] != '\000') {
438-
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_name);
438+
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_class);
439439
if (uri_handler == NULL) {
440440
zend_argument_value_error(6, "must be a valid URI parser name");
441441
return FALSE;
@@ -1159,7 +1159,7 @@ int make_http_soap_request(zval *this_ptr,
11591159
char *loc;
11601160

11611161
if ((loc = get_http_header_value(ZSTR_VAL(http_headers), "Location:")) != NULL) {
1162-
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_name);
1162+
uri_handler_t *uri_handler = php_uri_get_handler(uri_parser_class);
11631163
if (uri_handler == NULL) {
11641164
zend_argument_value_error(6, "must be a valid URI parser name");
11651165
return FALSE;

ext/soap/php_http.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int make_http_soap_request(zval *this_ptr,
2424
zend_string *location,
2525
char *soapaction,
2626
int soap_version,
27-
const zend_string *uri_parser_name,
27+
const zend_string *uri_parser_class,
2828
zval *response);
2929

3030
int proxy_authentication(zval* this_ptr, smart_str* soap_headers);

ext/soap/soap.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,7 @@ PHP_METHOD(SoapClient, __getLastResponseHeaders)
27692769
/* {{{ SoapClient::__doRequest() */
27702770
PHP_METHOD(SoapClient, __doRequest)
27712771
{
2772-
zend_string *buf, *location, *uri_parser_name = NULL;
2772+
zend_string *buf, *location, *uri_parser_class = NULL;
27732773
char *action;
27742774
size_t action_size;
27752775
zend_long version;
@@ -2780,17 +2780,17 @@ PHP_METHOD(SoapClient, __doRequest)
27802780
&buf,
27812781
&location,
27822782
&action, &action_size,
2783-
&version, &one_way, &uri_parser_name) == FAILURE) {
2783+
&version, &one_way, &uri_parser_class) == FAILURE) {
27842784
RETURN_THROWS();
27852785
}
27862786
if (SOAP_GLOBAL(features) & SOAP_WAIT_ONE_WAY_CALLS) {
27872787
one_way = 0;
27882788
}
27892789
if (one_way) {
2790-
if (make_http_soap_request(this_ptr, buf, location, action, version, uri_parser_name, NULL)) {
2790+
if (make_http_soap_request(this_ptr, buf, location, action, version, uri_parser_class, NULL)) {
27912791
RETURN_EMPTY_STRING();
27922792
}
2793-
} else if (make_http_soap_request(this_ptr, buf, location, action, version, uri_parser_name,
2793+
} else if (make_http_soap_request(this_ptr, buf, location, action, version, uri_parser_class,
27942794
return_value)) {
27952795
return;
27962796
}

ext/soap/soap.stub.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ public function __getLastRequestHeaders(): ?string {}
604604
public function __getLastResponseHeaders(): ?string {}
605605

606606
/** @tentative-return-type */
607-
public function __doRequest(string $request, string $location, string $action, int $version, bool $oneWay = false, ?string $uriParserName = null): ?string {}
607+
public function __doRequest(string $request, string $location, string $action, int $version, bool $oneWay = false, ?string $uriParserClass = null): ?string {}
608608

609609
/** @tentative-return-type */
610610
public function __setCookie(string $name, ?string $value = null): void {}

ext/soap/soap_arginfo.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/uri/php_lexbor.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ static void fill_errors(zval *errors)
8989
while ((lxb_error = lexbor_array_obj_pop(&lexbor_parser->log->list)) != NULL) {
9090
zval error;
9191
object_init_ex(&error, whatwg_error_ce);
92-
zend_update_property_string(whatwg_error_ce, Z_OBJ(error), "position", sizeof("position") - 1, (const char *) lxb_error->data);
93-
zend_update_property_long(whatwg_error_ce, Z_OBJ(error), "errorCode", sizeof("errorCode") - 1, lxb_error->id);
92+
zend_update_property_string(whatwg_error_ce, Z_OBJ(error), "context", sizeof("context") - 1, (const char *) lxb_error->data);
93+
94+
zval error_type;
95+
zend_string *error_str = zend_string_init((const char *) lxb_error->data,strlen((const char *) lxb_error->data), false);
96+
zend_enum_new(&error_type, whatwg_error_type_ce, error_str, NULL); // todo case name
97+
zend_update_property(whatwg_error_ce, Z_OBJ(error), "type", sizeof("type") - 1, &error_type);
9498

9599
add_next_index_zval(errors, &error);
96100
}

ext/uri/php_uri.c

+50-22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "php.h"
2222
#include "Zend/zend_interfaces.h"
2323
#include "Zend/zend_exceptions.h"
24+
#include "Zend/zend_enum.h"
2425
#include "main/php_ini.h"
2526

2627
#include "php_uri.h"
@@ -38,6 +39,7 @@ zend_class_entry *uri_exception_ce;
3839
zend_class_entry *uninitialized_uri_exception_ce;
3940
zend_class_entry *uri_operation_exception_ce;
4041
zend_class_entry *invalid_uri_exception_ce;
42+
zend_class_entry *whatwg_error_type_ce;
4143
zend_class_entry *whatwg_error_ce;
4244

4345
static zend_array uri_handlers;
@@ -181,25 +183,23 @@ PHPAPI void php_uri_free(uri_internal_t *internal_uri)
181183
efree(internal_uri);
182184
}
183185

184-
PHP_METHOD(Uri_WhatWgError, __construct)
186+
PHP_METHOD(Uri_WhatWg_WhatWgError, __construct)
185187
{
186-
zend_string *uri, *position;
187-
zend_long error;
188+
zend_string *context;
189+
zval *type;
188190

189-
ZEND_PARSE_PARAMETERS_START(3, 3)
190-
Z_PARAM_STR(uri)
191-
Z_PARAM_STR(position)
192-
Z_PARAM_LONG(error)
191+
ZEND_PARSE_PARAMETERS_START(2, 2)
192+
Z_PARAM_STR(context)
193+
Z_PARAM_OBJECT_OF_CLASS(type, whatwg_error_type_ce)
193194
ZEND_PARSE_PARAMETERS_END();
194195

195-
zend_update_property_str(whatwg_error_ce, Z_OBJ_P(ZEND_THIS), "uri", sizeof("uri") - 1, uri);
196-
zend_update_property_str(whatwg_error_ce, Z_OBJ_P(ZEND_THIS), "position", sizeof("position") - 1, position);
197-
zend_update_property_long(whatwg_error_ce, Z_OBJ_P(ZEND_THIS), "error", sizeof("error") - 1, error);
196+
zend_update_property_str(whatwg_error_ce, Z_OBJ_P(ZEND_THIS), "context", sizeof("context") - 1, context);
197+
zend_update_property(whatwg_error_ce, Z_OBJ_P(ZEND_THIS), "type", sizeof("type") - 1, type);
198198
}
199199

200200
PHPAPI void php_uri_instantiate_uri(
201201
INTERNAL_FUNCTION_PARAMETERS, const uri_handler_t *handler, const zend_string *uri_str, const zend_string *base_url_str,
202-
bool is_constructor, bool return_errors
202+
bool is_constructor, zval *errors_zv
203203
) {
204204
zval errors;
205205
ZVAL_UNDEF(&errors);
@@ -211,8 +211,16 @@ PHPAPI void php_uri_instantiate_uri(
211211
zval_ptr_dtor(&errors);
212212
RETURN_THROWS();
213213
} else {
214-
if (return_errors && Z_TYPE(errors) == IS_ARRAY) {
215-
RETURN_ZVAL(&errors, false, false);
214+
if (errors_zv != NULL && Z_TYPE(errors) == IS_ARRAY) {
215+
errors_zv = zend_try_array_init(errors_zv);
216+
if (!errors_zv) {
217+
RETURN_THROWS();
218+
}
219+
220+
zval *error;
221+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(errors_zv), error) {
222+
zend_hash_next_index_insert(Z_ARRVAL_P(errors_zv), error);
223+
} ZEND_HASH_FOREACH_END();
216224
}
217225

218226
zval_ptr_dtor(&errors);
@@ -235,11 +243,13 @@ PHPAPI void php_uri_instantiate_uri(
235243
static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
236244
{
237245
zend_string *uri_str, *base_url_str = NULL;
246+
zval *errors;
238247

239248
ZEND_PARSE_PARAMETERS_START(1, 2)
240249
Z_PARAM_PATH_STR(uri_str)
241250
Z_PARAM_OPTIONAL
242251
Z_PARAM_PATH_STR_OR_NULL(base_url_str)
252+
Z_PARAM_ZVAL(errors)
243253
ZEND_PARSE_PARAMETERS_END();
244254

245255
if (ZSTR_LEN(uri_str) == 0) {
@@ -252,7 +262,7 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor
252262
RETURN_THROWS();
253263
}
254264

255-
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, &uriparser_uri_handler, uri_str, base_url_str, is_constructor, false);
265+
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, &uriparser_uri_handler, uri_str, base_url_str, is_constructor, NULL);
256266
}
257267

258268
PHP_METHOD(Uri_Rfc3986Uri, parse)
@@ -268,11 +278,13 @@ PHP_METHOD(Uri_Rfc3986Uri, __construct)
268278
static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
269279
{
270280
zend_string *uri_str, *base_url_str = NULL;
281+
zval *errors = NULL;
271282

272-
ZEND_PARSE_PARAMETERS_START(1, 2)
283+
ZEND_PARSE_PARAMETERS_START(1, 3)
273284
Z_PARAM_PATH_STR(uri_str)
274285
Z_PARAM_OPTIONAL
275286
Z_PARAM_PATH_STR_OR_NULL(base_url_str)
287+
Z_PARAM_ZVAL(errors)
276288
ZEND_PARSE_PARAMETERS_END();
277289

278290
if (ZSTR_LEN(uri_str) == 0) {
@@ -285,7 +297,7 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
285297
RETURN_THROWS();
286298
}
287299

288-
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, &lexbor_uri_handler, uri_str, base_url_str, is_constructor, true);
300+
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, &lexbor_uri_handler, uri_str, base_url_str, is_constructor, errors);
289301
}
290302

291303
PHP_METHOD(Uri_WhatWgUri, parse)
@@ -378,7 +390,7 @@ PHP_METHOD(Uri_Rfc3986Uri, withFragment)
378390
URI_WITHER_STR(ZSTR_KNOWN(ZEND_STR_FRAGMENT));
379391
}
380392

381-
PHP_METHOD(Uri_Rfc3986Uri, equalsTo)
393+
PHP_METHOD(Uri_Rfc3986Uri, equals)
382394
{
383395
zend_object *that_object;
384396
bool exclude_fragment = true;
@@ -514,7 +526,7 @@ PHP_METHOD(Uri_Rfc3986Uri, toNormalizedString)
514526
internal_uri->handler->free_uri(new_uri);
515527
}
516528

517-
PHP_METHOD(Uri_Rfc3986Uri, __toString)
529+
PHP_METHOD(Uri_Rfc3986Uri, toString)
518530
{
519531
ZEND_PARSE_PARAMETERS_NONE();
520532

@@ -525,6 +537,23 @@ PHP_METHOD(Uri_Rfc3986Uri, __toString)
525537
RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, false));
526538
}
527539

540+
PHP_METHOD(Uri_Rfc3986Uri, resolve)
541+
{
542+
zend_string *uri_str;
543+
544+
ZEND_PARSE_PARAMETERS_START(1, 1) \
545+
Z_PARAM_PATH_STR(uri_str) \
546+
ZEND_PARSE_PARAMETERS_END(); \
547+
548+
zend_object *this_object = Z_OBJ_P(ZEND_THIS);
549+
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
550+
URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, this_object);
551+
552+
zend_string *base_uri_str = internal_uri->handler->uri_to_string(internal_uri->uri, false); // TODO optimize by not reparsing the base URI
553+
554+
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, internal_uri->handler, uri_str, base_uri_str, true, NULL);
555+
}
556+
528557
PHP_METHOD(Uri_Rfc3986Uri, __serialize)
529558
{
530559
ZEND_PARSE_PARAMETERS_NONE();
@@ -839,9 +868,7 @@ zend_result uri_handler_register(const uri_handler_t *uri_handler)
839868

840869
static PHP_MINIT_FUNCTION(uri)
841870
{
842-
register_php_uri_symbols(module_number);
843-
844-
uri_interface_ce = register_class_Uri_UriInterface(zend_ce_stringable);
871+
uri_interface_ce = register_class_Uri_Uri();
845872

846873
rfc3986_uri_ce = register_class_Uri_Rfc3986Uri(uri_interface_ce);
847874
php_uri_implementation_set_object_handlers(rfc3986_uri_ce, &rfc3986_uri_object_handlers);
@@ -853,7 +880,8 @@ static PHP_MINIT_FUNCTION(uri)
853880
uninitialized_uri_exception_ce = register_class_Uri_UninitializedUriException(uri_exception_ce);
854881
uri_operation_exception_ce = register_class_Uri_UriOperationException(uri_exception_ce);
855882
invalid_uri_exception_ce = register_class_Uri_InvalidUriException(uri_exception_ce);
856-
whatwg_error_ce = register_class_Uri_WhatWgError();
883+
whatwg_error_ce = register_class_Uri_WhatWg_WhatWgError();
884+
whatwg_error_type_ce = register_class_Uri_WhatWg_WhatWgErrorType();
857885

858886
zend_hash_init(&uri_handlers, 4, NULL, ZVAL_PTR_DTOR, true);
859887

ext/uri/php_uri.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ PHPAPI void php_uri_free(uri_internal_t *internal_uri);
4040

4141
PHPAPI void php_uri_instantiate_uri(
4242
INTERNAL_FUNCTION_PARAMETERS, const uri_handler_t *handler, const zend_string *uri_str, const zend_string *base_url_str,
43-
bool is_constructor, bool return_errors
43+
bool is_constructor, zval *errors_zv
4444
);
4545
PHPAPI void php_uri_implementation_set_object_handlers(zend_class_entry *ce, zend_object_handlers *object_handlers);
4646

0 commit comments

Comments
 (0)