Skip to content

Commit 889f381

Browse files
committed
Cherry pick some recent lexbor changes
The following changes are cherry-picked: - lexbor/lexbor@c608466 core/str.c: Fix undefined behavior in function lexbor_str_append - lexbor/lexbor@92260fd URL: fixed hostname setter if port is specified.
1 parent a22dc67 commit 889f381

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

ext/lexbor/lexbor/core/str.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ lexbor_str_append(lexbor_str_t *str, lexbor_mraw_t *mraw,
133133
{
134134
lxb_char_t *data_begin;
135135

136+
if (length == 0) {
137+
return str->data;
138+
}
139+
136140
lexbor_str_check_size_arg_m(str, lexbor_str_size(str),
137141
mraw, (length + 1), NULL);
138142

ext/lexbor/lexbor/url/url.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ lxb_url_parse_basic_h(lxb_url_parser_t *parser, lxb_url_t *url,
18181818
}
18191819

18201820
if (override_state == LXB_URL_STATE_HOSTNAME_STATE) {
1821-
lxb_url_parse_return(orig_data, buf, LXB_STATUS_OK);
1821+
lxb_url_parse_return(orig_data, buf, LXB_STATUS_ERROR);
18221822
}
18231823

18241824
status = lxb_url_host_parse(parser, begin, p, &url->host,

ext/uri/tests/026.phpt

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@ uri
88
$url1 = Uri\WhatWg\Url::parse("https://example.com");
99
$url2 = $url1->withHost("test.com");
1010
$url3 = $url2->withHost("t%65st.com"); // test.com
11-
$url4 = $url3->withHost("test.com:8080");
11+
try {
12+
$url3->withHost("test.com:8080");
13+
} catch (Uri\WhatWg\InvalidUrlException $e) {
14+
echo $e->getMessage() . "\n";
15+
}
1216

1317
var_dump($url1->getAsciiHost());
1418
var_dump($url2->getAsciiHost());
1519
var_dump($url3->getAsciiHost());
16-
var_dump($url4->getAsciiHost());
17-
var_dump($url4->getPort());
1820

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

25-
var_dump($url4->withHost("t:s/t.com"));
27+
try {
28+
$url3->withHost("t:s/t.com"); // t:s/t.com
29+
} catch (Uri\WhatWg\InvalidUrlException $e) {
30+
echo $e->getMessage() . "\n";
31+
}
2632

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

3945
?>
4046
--EXPECTF--
47+
The specified host is malformed
4148
string(11) "example.com"
4249
string(8) "test.com"
4350
string(8) "test.com"
44-
string(8) "test.com"
45-
NULL
4651
The specified host is malformed (DomainInvalidCodePoint)
47-
object(Uri\WhatWg\Url)#%d (%d) {
48-
["scheme"]=>
49-
string(5) "https"
50-
["username"]=>
51-
NULL
52-
["password"]=>
53-
NULL
54-
["host"]=>
55-
string(8) "test.com"
56-
["port"]=>
57-
NULL
58-
["path"]=>
59-
string(1) "/"
60-
["query"]=>
61-
NULL
62-
["fragment"]=>
63-
NULL
64-
}
52+
The specified host is malformed
6553
The specified host is malformed (HostMissing)
6654
string(7) "foo.com"
6755
string(8) "test.com"

0 commit comments

Comments
 (0)