Skip to content
Closed
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
4 changes: 4 additions & 0 deletions ext/lexbor/lexbor/core/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ lexbor_str_append(lexbor_str_t *str, lexbor_mraw_t *mraw,
{
lxb_char_t *data_begin;

if (length == 0) {
return str->data;
}

lexbor_str_check_size_arg_m(str, lexbor_str_size(str),
mraw, (length + 1), NULL);

Expand Down
2 changes: 1 addition & 1 deletion ext/lexbor/lexbor/url/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ lxb_url_parse_basic_h(lxb_url_parser_t *parser, lxb_url_t *url,
}

if (override_state == LXB_URL_STATE_HOSTNAME_STATE) {
lxb_url_parse_return(orig_data, buf, LXB_STATUS_OK);
lxb_url_parse_return(orig_data, buf, LXB_STATUS_ERROR);
}

status = lxb_url_host_parse(parser, begin, p, &url->host,
Expand Down
4 changes: 3 additions & 1 deletion ext/uri/php_lexbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ static zend_result lexbor_read_host(const struct uri_internal_t *internal_uri, u
smart_str_appendc(&host_str, ']');

ZVAL_NEW_STR(retval, smart_str_extract(&host_str));
} else if (lexbor_uri->host.type != LXB_URL_HOST_TYPE_EMPTY && lexbor_uri->host.type != LXB_URL_HOST_TYPE__UNDEF) {
} else if (lexbor_uri->host.type == LXB_URL_HOST_TYPE_EMPTY) {
ZVAL_EMPTY_STRING(retval);
} else if (lexbor_uri->host.type != LXB_URL_HOST_TYPE__UNDEF) {
switch (read_mode) {
case URI_COMPONENT_READ_NORMALIZED_UNICODE: {
smart_str host_str = {0};
Expand Down
2 changes: 1 addition & 1 deletion ext/uri/php_uriparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result uriparser_read_host(const uri_internal
UriUriA *uriparser_uri = uriparser_read_uri(internal_uri->uri, read_mode);
ZEND_ASSERT(uriparser_uri != NULL);

if (uriparser_uri->hostText.first != NULL && uriparser_uri->hostText.afterLast != NULL && get_text_range_length(&uriparser_uri->hostText) > 0) {
if (uriparser_uri->hostText.first != NULL && uriparser_uri->hostText.afterLast != NULL) {
if (uriparser_uri->hostData.ip6 != NULL || uriparser_uri->hostData.ipFuture.first != NULL) {
/* the textual representation of the host is always accessible in the .hostText field no matter what the host is */
smart_str host_str = {0};
Expand Down
40 changes: 39 additions & 1 deletion ext/uri/tests/003.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Parse URL exotic URLs
Parse special URIs
--EXTENSIONS--
uri
--FILE--
Expand All @@ -8,6 +8,8 @@ uri
var_dump(Uri\Rfc3986\Uri::parse("http://username:password@héééostname:9090/gah/../path?arg=vaéue#anchor"));
var_dump(Uri\WhatWg\Url::parse("http://username:password@héééostname:9090/gah/../path?arg=vaéue#anchor"));

var_dump(Uri\Rfc3986\Uri::parse("//host123/"));
var_dump(Uri\Rfc3986\Uri::parse("///foo/"));
var_dump(Uri\Rfc3986\Uri::parse("/page:1"));
var_dump(Uri\WhatWg\Url::parse("/page:1"));

Expand All @@ -32,6 +34,42 @@ object(Uri\WhatWg\Url)#%d (%d) {
["fragment"]=>
string(6) "anchor"
}
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
NULL
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(7) "host123"
["port"]=>
NULL
["path"]=>
string(1) "/"
["query"]=>
NULL
["fragment"]=>
NULL
}
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
NULL
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(0) ""
["port"]=>
NULL
["path"]=>
string(5) "/foo/"
["query"]=>
NULL
["fragment"]=>
NULL
}
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
NULL
Expand Down
4 changes: 2 additions & 2 deletions ext/uri/tests/012.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object(Uri\Rfc3986\Uri)#%d (%d) {
["password"]=>
NULL
["host"]=>
NULL
string(0) ""
["port"]=>
NULL
["path"]=>
Expand All @@ -75,7 +75,7 @@ object(Uri\WhatWg\Url)#%d (%d) {
["password"]=>
NULL
["host"]=>
NULL
string(0) ""
["port"]=>
NULL
["path"]=>
Expand Down
38 changes: 13 additions & 25 deletions ext/uri/tests/026.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ uri
$url1 = Uri\WhatWg\Url::parse("https://example.com");
$url2 = $url1->withHost("test.com");
$url3 = $url2->withHost("t%65st.com"); // test.com
$url4 = $url3->withHost("test.com:8080");
try {
$url3->withHost("test.com:8080");
} catch (Uri\WhatWg\InvalidUrlException $e) {
echo $e->getMessage() . "\n";
}

var_dump($url1->getAsciiHost());
var_dump($url2->getAsciiHost());
var_dump($url3->getAsciiHost());
var_dump($url4->getAsciiHost());
var_dump($url4->getPort());

try {
$url4->withHost("t%3As%2Ft.com"); // t:s/t.com
$url3->withHost("t%3As%2Ft.com"); // t:s/t.com
} catch (Uri\WhatWg\InvalidUrlException $e) {
echo $e->getMessage() . "\n";
}

var_dump($url4->withHost("t:s/t.com"));
try {
$url3->withHost("t:s/t.com"); // t:s/t.com
} catch (Uri\WhatWg\InvalidUrlException $e) {
echo $e->getMessage() . "\n";
}

try {
$url2->withHost(null);
Expand All @@ -38,30 +44,12 @@ var_dump($url2->getAsciiHost());

?>
--EXPECTF--
The specified host is malformed
string(11) "example.com"
string(8) "test.com"
string(8) "test.com"
string(8) "test.com"
NULL
The specified host is malformed (DomainInvalidCodePoint)
object(Uri\WhatWg\Url)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(8) "test.com"
["port"]=>
NULL
["path"]=>
string(1) "/"
["query"]=>
NULL
["fragment"]=>
NULL
}
The specified host is malformed
The specified host is malformed (HostMissing)
string(7) "foo.com"
string(8) "test.com"