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,16 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setHost() - error - contains a forbidden host code point
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();

try {
$builder->setHost("exa mple.com");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified host is malformed (HostInvalidCodePoint)
16 changes: 16 additions & 0 deletions ext/uri/tests/whatwg/builder/host_error_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setHost() - error - contains a null byte
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();

try {
$builder->setHost("\0bébé.be");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified host is malformed (HostInvalidCodePoint)
16 changes: 16 additions & 0 deletions ext/uri/tests/whatwg/builder/host_error_port_delimiter.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setHost() - error - contains a port delimiter
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();

try {
$builder->setHost("example.com:8080");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified host is malformed (HostInvalidCodePoint)
5 changes: 4 additions & 1 deletion ext/uri/uri_parser_whatwg.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,13 @@ ZEND_ATTRIBUTE_NONNULL zend_result php_uri_parser_whatwg_host_validate(const zen

/* Validate the entire host before the hostname setter can stop at a URL delimiter.
* Backslash is a delimiter only for special URLs, but is also forbidden in opaque hosts.
* The other forbidden host code points are rejected by every host parser.
* https://url.spec.whatwg.org/#hostname-state
* https://url.spec.whatwg.org/#opaque-host-parser */
for (const char *p = first; p < last; p++) {
if (*p == '/' || *p == '?' || *p == '#' || *p == '\\') {
if (*p == '/' || *p == '?' || *p == '#' || *p == '\\'
|| *p == '\0' || *p == ' ' || *p == '<' || *p == '>' || *p == '@' || *p == '^' || *p == '|'
|| (*first != '[' && (*p == ':' || *p == '[' || *p == ']'))) {
return php_uri_parser_whatwg_component_error("host", LXB_URL_ERROR_TYPE_HOST_INVALID_CODE_POINT);
}
}
Expand Down
Loading