Skip to content

Commit 8c50acd

Browse files
committed
Address review feedback + fixes
1 parent aa4b203 commit 8c50acd

39 files changed

Lines changed: 480 additions & 418 deletions

ext/lexbor/lexbor/url/url.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,6 @@ static bool
595595
lxb_url_is_ipv4(lxb_url_parser_t *parser, const lxb_char_t *data,
596596
const lxb_char_t *end);
597597

598-
static lxb_status_t
599-
lxb_url_ipv6_parse(lxb_url_parser_t *parser, const lxb_char_t *data,
600-
const lxb_char_t *end, uint16_t *ipv6);
601-
602598
static lxb_status_t
603599
lxb_url_ipv4_in_ipv6_parse(lxb_url_parser_t *parser, const lxb_char_t **data,
604600
const lxb_char_t *end, uint16_t **pieces);
@@ -3752,7 +3748,7 @@ lxb_url_is_ipv4(lxb_url_parser_t *parser, const lxb_char_t *data,
37523748
return status != LXB_STATUS_ERROR;
37533749
}
37543750

3755-
static lxb_status_t
3751+
lxb_status_t
37563752
lxb_url_ipv6_parse(lxb_url_parser_t *parser, const lxb_char_t *data,
37573753
const lxb_char_t *end, uint16_t *ipv6)
37583754
{

ext/lexbor/lexbor/url/url.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ typedef lexbor_action_t
197197
(*lxb_url_search_params_match_f)(lxb_url_search_params_t *sp,
198198
lxb_url_search_entry_t *entry, void *ctx);
199199

200+
/*
201+
* Parse an IPv6 address,
202+
*
203+
* @return lxb_status_t LXB_STATUS_OK if successful, otherwise NULL.
204+
*/
205+
lxb_status_t
206+
lxb_url_ipv6_parse(lxb_url_parser_t *parser, const lxb_char_t *data,
207+
const lxb_char_t *end, uint16_t *ipv6);
200208

201209
/*
202210
* Create lxb_url_parser_t object.

ext/uri/php_uri.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ PHP_METHOD(Uri_WhatWg_UrlBuilder, setHost)
13051305
php_uri_builder_set_component_string_or_null(
13061306
INTERNAL_FUNCTION_PARAM_PASSTHRU,
13071307
ZEND_STRL("host"),
1308-
php_uri_parser_whatwg_validate_none
1308+
php_uri_parser_whatwg_validate_host
13091309
);
13101310
}
13111311

ext/uri/tests/whatwg/builder/basic_error_with_base.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Test Uri\WhatWg\UrlBuilder basic - error - with base URL
33
--FILE--
44
<?php
55

6-
$builder = new Uri\WhatWg\UrlBuilder()
7-
->setPath("/foo/bar/baz");
6+
$builder = new Uri\WhatWg\UrlBuilder();
7+
$builder->setPath("/foo/bar/baz");
88

99
try {
1010
$builder->build(new Uri\WhatWg\Url("/foo/bar"));

ext/uri/tests/whatwg/builder/basic_success_with_base.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Test Uri\WhatWg\UrlBuilder basic - success - with base URL
33
--FILE--
44
<?php
55

6-
$builder = new Uri\WhatWg\UrlBuilder()
7-
->setPath("/foo/bar/baz");
6+
$builder = new Uri\WhatWg\UrlBuilder();
7+
$builder->setPath("/foo/bar/baz");
88
$url = $builder->build(new Uri\WhatWg\Url("https://example.com"));
99

1010
var_dump($url->toAsciiString());

ext/uri/tests/whatwg/builder/fragment_error_unicode_char.phpt

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,34 @@ Test Uri\WhatWg\UrlBuilder::setFragment() - error - contains Unicode character
44
<?php
55

66
$builder = new Uri\WhatWg\UrlBuilder();
7+
$builder->setScheme("https");
8+
$builder->setHost("example.com");
9+
$builder->setFragment("főő");
10+
$url = $builder->build();
711

8-
try {
9-
$builder->setFragment("főő");
10-
} catch (Throwable $e) {
11-
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
12-
}
12+
var_dump($url->toAsciiString());
13+
var_dump($url);
14+
var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));
1315

1416
?>
15-
--EXPECT--
16-
17+
--EXPECTF--
18+
string(34) "https://example.com/#f%C5%91%C5%91"
19+
object(Uri\WhatWg\Url)#%d (%d) {
20+
["scheme"]=>
21+
string(5) "https"
22+
["username"]=>
23+
NULL
24+
["password"]=>
25+
NULL
26+
["host"]=>
27+
string(11) "example.com"
28+
["port"]=>
29+
NULL
30+
["path"]=>
31+
string(1) "/"
32+
["query"]=>
33+
NULL
34+
["fragment"]=>
35+
string(13) "f%C5%91%C5%91"
36+
}
37+
bool(true)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Test Uri\WhatWg\UrlBuilder::setHost() - error - missing IPv6 closing brace of an opaque host
3+
--FILE--
4+
<?php
5+
6+
$builder = new Uri\WhatWg\UrlBuilder();
7+
$builder->setScheme("scheme");
8+
9+
try {
10+
$builder->setHost("[2001:%30db8:85a3:0000:0000:8a2e:0370:7334");
11+
} catch (Throwable $e) {
12+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
13+
}
14+
15+
?>
16+
--EXPECT--
17+
Uri\WhatWg\InvalidUrlException: The specified host is malformed (Ipv6Unclosed)

ext/uri/tests/whatwg/builder/host_error_ipv6_closing_brace.phpt renamed to ext/uri/tests/whatwg/builder/host_error_ipv6_closing_brace_special.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
--TEST--
2-
Test Uri\WhatWg\UrlBuilder::setHost() - error - missing IPv6 closing brace
2+
Test Uri\WhatWg\UrlBuilder::setHost() - error - missing IPv6 closing brace of a special host
33
--FILE--
44
<?php
55

66
$builder = new Uri\WhatWg\UrlBuilder();
77
$builder->setScheme("https");
8-
$builder->setHost("[2001:%30db8:85a3:0000:0000:8a2e:0370:7334");
98

109
try {
11-
$builder->build();
10+
$builder->setHost("[2001:%30db8:85a3:0000:0000:8a2e:0370:7334");
1211
} catch (Throwable $e) {
1312
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
1413
}

ext/uri/tests/whatwg/builder/host_error_percent_encoding2.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ Test Uri\WhatWg\UrlBuilder::setHost() - error - invalid percent encoded octet in
55

66
$builder = new Uri\WhatWg\UrlBuilder();
77
$builder->setScheme("https");
8-
$builder->setHost("[2001:%308:85a3:0000:0000:8a2e:0370:7334]");
98

109
try {
11-
$builder->build();
10+
$builder->setHost("[2001:%308:85a3:0000:0000:8a2e:0370:7334]");
1211
} catch (Throwable $e) {
1312
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
1413
}

ext/uri/tests/whatwg/builder/port_success_file_scheme.phpt renamed to ext/uri/tests/whatwg/builder/host_success_file.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
--TEST--
2-
Test Uri\WhatWg\UrlBuilder::setPort() - success - ignored for file scheme
2+
Test Uri\WhatWg\UrlBuilder::setHost() - success - file scheme
33
--FILE--
44
<?php
55

66
$builder = new Uri\WhatWg\UrlBuilder();
77
$builder->setScheme("file");
8-
$builder->setPath("C:/a.txt");
9-
$builder->setPort(443);
8+
$builder->setHost("example.com");
109
$url = $builder->build();
1110

1211
var_dump($url->toAsciiString());
@@ -15,7 +14,7 @@ var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));
1514

1615
?>
1716
--EXPECTF--
18-
string(16) "file:///C:/a.txt"
17+
string(19) "file://example.com/"
1918
object(Uri\WhatWg\Url)#%d (%d) {
2019
["scheme"]=>
2120
string(4) "file"
@@ -24,14 +23,15 @@ object(Uri\WhatWg\Url)#%d (%d) {
2423
["password"]=>
2524
NULL
2625
["host"]=>
27-
string(0) ""
26+
string(11) "example.com"
2827
["port"]=>
2928
NULL
3029
["path"]=>
31-
string(9) "/C:/a.txt"
30+
string(1) "/"
3231
["query"]=>
3332
NULL
3433
["fragment"]=>
3534
NULL
3635
}
3736
bool(true)
37+

0 commit comments

Comments
 (0)