Cherry pick some recent lexbor changes

The following changes are cherry-picked:
- c60846689d core/str.c: Fix undefined behavior in function lexbor_str_append
- 92260fd670 URL: fixed hostname setter if port is specified.
This commit is contained in:
Máté Kocsis 2025-07-14 23:21:07 +02:00
parent a22dc67a21
commit 889f38135d
No known key found for this signature in database
GPG key ID: FD055E41728BF310
3 changed files with 23 additions and 31 deletions

View file

@ -133,6 +133,10 @@ lexbor_str_append(lexbor_str_t *str, lexbor_mraw_t *mraw,
{ {
lxb_char_t *data_begin; lxb_char_t *data_begin;
if (length == 0) {
return str->data;
}
lexbor_str_check_size_arg_m(str, lexbor_str_size(str), lexbor_str_check_size_arg_m(str, lexbor_str_size(str),
mraw, (length + 1), NULL); mraw, (length + 1), NULL);

View file

@ -1818,7 +1818,7 @@ again:
} }
if (override_state == LXB_URL_STATE_HOSTNAME_STATE) { 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, status = lxb_url_host_parse(parser, begin, p, &url->host,

View file

@ -8,21 +8,27 @@ uri
$url1 = Uri\WhatWg\Url::parse("https://example.com"); $url1 = Uri\WhatWg\Url::parse("https://example.com");
$url2 = $url1->withHost("test.com"); $url2 = $url1->withHost("test.com");
$url3 = $url2->withHost("t%65st.com"); // test.com $url3 = $url2->withHost("t%65st.com"); // test.com
$url4 = $url3->withHost("test.com:8080");
var_dump($url1->getAsciiHost());
var_dump($url2->getAsciiHost());
var_dump($url3->getAsciiHost());
var_dump($url4->getAsciiHost());
var_dump($url4->getPort());
try { try {
$url4->withHost("t%3As%2Ft.com"); // t:s/t.com $url3->withHost("test.com:8080");
} catch (Uri\WhatWg\InvalidUrlException $e) { } catch (Uri\WhatWg\InvalidUrlException $e) {
echo $e->getMessage() . "\n"; echo $e->getMessage() . "\n";
} }
var_dump($url4->withHost("t:s/t.com")); var_dump($url1->getAsciiHost());
var_dump($url2->getAsciiHost());
var_dump($url3->getAsciiHost());
try {
$url3->withHost("t%3As%2Ft.com"); // t:s/t.com
} catch (Uri\WhatWg\InvalidUrlException $e) {
echo $e->getMessage() . "\n";
}
try {
$url3->withHost("t:s/t.com"); // t:s/t.com
} catch (Uri\WhatWg\InvalidUrlException $e) {
echo $e->getMessage() . "\n";
}
try { try {
$url2->withHost(null); $url2->withHost(null);
@ -38,30 +44,12 @@ var_dump($url2->getAsciiHost());
?> ?>
--EXPECTF-- --EXPECTF--
The specified host is malformed
string(11) "example.com" string(11) "example.com"
string(8) "test.com" string(8) "test.com"
string(8) "test.com" string(8) "test.com"
string(8) "test.com"
NULL
The specified host is malformed (DomainInvalidCodePoint) The specified host is malformed (DomainInvalidCodePoint)
object(Uri\WhatWg\Url)#%d (%d) { The specified host is malformed
["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 (HostMissing) The specified host is malformed (HostMissing)
string(7) "foo.com" string(7) "foo.com"
string(8) "test.com" string(8) "test.com"