Skip to content

Commit e4e29df

Browse files
committed
Clean Lexbor logs before each wither call
Otherwise previous errors may be recorded and returned the next time a UrlValidationError is created.
1 parent c8c48f5 commit e4e29df

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
@@ -265,6 +265,8 @@ static zend_result php_uri_parser_whatwg_scheme_write(void *uri, zval *value, zv
265265

266266
zval_string_or_null_to_lexbor_str(value, &str);
267267

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

@@ -300,6 +302,8 @@ static zend_result php_uri_parser_whatwg_username_write(void *uri, zval *value,
300302

301303
zval_string_or_null_to_lexbor_str(value, &str);
302304

305+
lxb_url_parser_clean(&lexbor_parser);
306+
303307
if (lxb_url_api_username_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
304308
throw_invalid_url_exception_during_write(errors, "username");
305309

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

330334
zval_string_or_null_to_lexbor_str(value, &str);
331335

336+
lxb_url_parser_clean(&lexbor_parser);
337+
332338
if (lxb_url_api_password_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
333339
throw_invalid_url_exception_during_write(errors, "password");
334340

@@ -389,6 +395,8 @@ static zend_result php_uri_parser_whatwg_host_write(void *uri, zval *value, zval
389395

390396
zval_string_or_null_to_lexbor_str(value, &str);
391397

398+
lxb_url_parser_clean(&lexbor_parser);
399+
392400
if (lxb_url_api_hostname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
393401
throw_invalid_url_exception_during_write(errors, "host");
394402

@@ -418,6 +426,8 @@ static zend_result php_uri_parser_whatwg_port_write(void *uri, zval *value, zval
418426

419427
zval_long_or_null_to_lexbor_str(value, &str);
420428

429+
lxb_url_parser_clean(&lexbor_parser);
430+
421431
if (lxb_url_api_port_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
422432
throw_invalid_url_exception_during_write(errors, "port");
423433

@@ -447,6 +457,8 @@ static zend_result php_uri_parser_whatwg_path_write(void *uri, zval *value, zval
447457

448458
zval_string_or_null_to_lexbor_str(value, &str);
449459

460+
lxb_url_parser_clean(&lexbor_parser);
461+
450462
if (lxb_url_api_pathname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
451463
throw_invalid_url_exception_during_write(errors, "path");
452464

@@ -476,6 +488,8 @@ static zend_result php_uri_parser_whatwg_query_write(void *uri, zval *value, zva
476488

477489
zval_string_or_null_to_lexbor_str(value, &str);
478490

491+
lxb_url_parser_clean(&lexbor_parser);
492+
479493
if (lxb_url_api_search_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
480494
throw_invalid_url_exception_during_write(errors, "query string");
481495

@@ -505,6 +519,8 @@ static zend_result php_uri_parser_whatwg_fragment_write(void *uri, zval *value,
505519

506520
zval_string_or_null_to_lexbor_str(value, &str);
507521

522+
lxb_url_parser_clean(&lexbor_parser);
523+
508524
if (lxb_url_api_hash_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
509525
throw_invalid_url_exception_during_write(errors, "fragment");
510526

0 commit comments

Comments
 (0)