Skip to content

Commit 78952c7

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Clean Lexbor logs before each Uri\WhatWg\Url wither call (#22276)
2 parents bd02ae9 + c9cb1f9 commit 78952c7

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Test Uri\WhatWg\Url component modification - error - modifying multiple components with warnings before throwing an exception
3+
--FILE--
4+
<?php
5+
6+
$url = new Uri\WhatWg\Url("https://example.com")
7+
->withScheme("\tscheme")
8+
->withHost("\tex.com")
9+
->withQuery("\refoo=bar")
10+
->withFragment("\nfoo");
11+
12+
try {
13+
$url->withScheme("0");
14+
} catch (Throwable $e) {
15+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
16+
var_dump($e->errors);
17+
}
18+
19+
?>
20+
--EXPECT--
21+
Uri\WhatWg\InvalidUrlException: The specified scheme is malformed
22+
array(0) {
23+
}

ext/uri/uri_parser_whatwg.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ static zend_result php_uri_parser_whatwg_scheme_write(void *uri, zval *value, zv
264264

265265
zval_string_or_null_to_lexbor_str(value, &str);
266266

267+
lxb_url_parser_clean(&lexbor_parser);
268+
267269
if (lxb_url_api_protocol_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
268270
throw_invalid_url_exception_during_write(errors, "scheme");
269271

@@ -304,6 +306,8 @@ static zend_result php_uri_parser_whatwg_username_write(void *uri, zval *value,
304306

305307
zval_string_or_null_to_lexbor_str(value, &str);
306308

309+
lxb_url_parser_clean(&lexbor_parser);
310+
307311
if (lxb_url_api_username_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
308312
throw_invalid_url_exception_during_write(errors, "username");
309313

@@ -333,6 +337,8 @@ static zend_result php_uri_parser_whatwg_password_write(void *uri, zval *value,
333337

334338
zval_string_or_null_to_lexbor_str(value, &str);
335339

340+
lxb_url_parser_clean(&lexbor_parser);
341+
336342
if (lxb_url_api_password_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
337343
throw_invalid_url_exception_during_write(errors, "password");
338344

@@ -418,6 +424,8 @@ static zend_result php_uri_parser_whatwg_host_write(void *uri, zval *value, zval
418424

419425
zval_string_or_null_to_lexbor_str(value, &str);
420426

427+
lxb_url_parser_clean(&lexbor_parser);
428+
421429
if (lxb_url_api_hostname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
422430
throw_invalid_url_exception_during_write(errors, "host");
423431

@@ -447,6 +455,8 @@ static zend_result php_uri_parser_whatwg_port_write(void *uri, zval *value, zval
447455

448456
zval_long_or_null_to_lexbor_str(value, &str);
449457

458+
lxb_url_parser_clean(&lexbor_parser);
459+
450460
if (lxb_url_api_port_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
451461
throw_invalid_url_exception_during_write(errors, "port");
452462

@@ -476,6 +486,8 @@ static zend_result php_uri_parser_whatwg_path_write(void *uri, zval *value, zval
476486

477487
zval_string_or_null_to_lexbor_str(value, &str);
478488

489+
lxb_url_parser_clean(&lexbor_parser);
490+
479491
if (lxb_url_api_pathname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
480492
throw_invalid_url_exception_during_write(errors, "path");
481493

@@ -505,6 +517,8 @@ static zend_result php_uri_parser_whatwg_query_write(void *uri, zval *value, zva
505517

506518
zval_string_or_null_to_lexbor_str(value, &str);
507519

520+
lxb_url_parser_clean(&lexbor_parser);
521+
508522
if (lxb_url_api_search_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
509523
throw_invalid_url_exception_during_write(errors, "query string");
510524

@@ -534,6 +548,8 @@ static zend_result php_uri_parser_whatwg_fragment_write(void *uri, zval *value,
534548

535549
zval_string_or_null_to_lexbor_str(value, &str);
536550

551+
lxb_url_parser_clean(&lexbor_parser);
552+
537553
if (lxb_url_api_hash_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
538554
throw_invalid_url_exception_during_write(errors, "fragment");
539555

0 commit comments

Comments
 (0)