Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Test Uri\WhatWg\Url component modification - error - modifying multiple components with warnings before throwing an exception
--FILE--
<?php

$url = new Uri\WhatWg\Url("https://example.com")
->withScheme("\tscheme")
->withHost("\tex.com")
->withQuery("\refoo=bar")
->withFragment("\nfoo");

try {
$url->withScheme("0");
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
var_dump($e->errors);
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified scheme is malformed
array(0) {
}
16 changes: 16 additions & 0 deletions ext/uri/uri_parser_whatwg.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ static zend_result php_uri_parser_whatwg_scheme_write(void *uri, zval *value, zv

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_protocol_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "scheme");

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

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_username_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "username");

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

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_password_set(lexbor_uri, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "password");

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

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_hostname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "host");

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

zval_long_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_port_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "port");

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

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_pathname_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "path");

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

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_search_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "query string");

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

zval_string_or_null_to_lexbor_str(value, &str);

lxb_url_parser_clean(&lexbor_parser);

if (lxb_url_api_hash_set(lexbor_uri, &lexbor_parser, str.data, str.length) != LXB_STATUS_OK) {
throw_invalid_url_exception_during_write(errors, "fragment");

Expand Down
Loading