Skip to content

Commit 9ca23f1

Browse files
committed
Review fixes
1 parent 0dc9669 commit 9ca23f1

6 files changed

Lines changed: 85 additions & 10 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $builder->setPath("/foo/bar/baz");
99
try {
1010
$builder->build(new Uri\WhatWg\Url("scheme:opaque-path"));
1111
} catch (Throwable $e) {
12-
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
12+
echo $e::class, ': ', $e->getMessage(), "\n";
1313
}
1414

1515
?>
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 basic - error - URL consisting of only a password with base URL
3+
--FILE--
4+
<?php
5+
6+
$builder = new Uri\WhatWg\UrlBuilder();
7+
$builder->setPassword("password");
8+
9+
try {
10+
$builder->build(new Uri\WhatWg\Url("https://example.com"));
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), "\n";
13+
}
14+
15+
?>
16+
--EXPECT--
17+
Uri\WhatWg\InvalidUrlException: The specified URL cannot have password
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 basic - error - URL consisting of only a port with base URL
3+
--FILE--
4+
<?php
5+
6+
$builder = new Uri\WhatWg\UrlBuilder();
7+
$builder->setPort(123);
8+
9+
try {
10+
$builder->build(new Uri\WhatWg\Url("https://example.com"));
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), "\n";
13+
}
14+
15+
?>
16+
--EXPECT--
17+
Uri\WhatWg\InvalidUrlException: The specified URL cannot have port
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 basic - error - URL consisting of only a username with base URL
3+
--FILE--
4+
<?php
5+
6+
$builder = new Uri\WhatWg\UrlBuilder();
7+
$builder->setUsername("username");
8+
9+
try {
10+
$builder->build(new Uri\WhatWg\Url("https://example.com"));
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), "\n";
13+
}
14+
15+
?>
16+
--EXPECT--
17+
Uri\WhatWg\InvalidUrlException: The specified URL cannot have username

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));
1515

1616
?>
1717
--EXPECTF--
18-
string(45) "https://user:pass@example.net:124/foo/bar/baz"
18+
string(35) "https://example.net:124/foo/bar/baz"
1919
object(Uri\WhatWg\Url)#%d (%d) {
2020
["scheme"]=>
2121
string(5) "https"
2222
["username"]=>
23-
string(4) "user"
23+
NULL
2424
["password"]=>
25-
string(4) "pass"
25+
NULL
2626
["host"]=>
2727
string(11) "example.net"
2828
["port"]=>

ext/uri/uri_parser_whatwg.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,14 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2, 3, 4, 5, 6, 7, 8, 9) lxb_url_t *php_uri_parser
10011001
if (status != LXB_STATUS_OK) {
10021002
goto failure;
10031003
}
1004+
} else if (lexbor_base_url->username.data != NULL) {
1005+
zval zv;
1006+
ZVAL_NULL(&zv);
1007+
const zend_result result = php_uri_parser_whatwg_username_write(lexbor_url, &zv, NULL);
1008+
php_uri_parser_whatwg_build_errors(&errors);
1009+
if (result == FAILURE) {
1010+
goto failure;
1011+
}
10041012
}
10051013

10061014
if (Z_TYPE_P(password) == IS_STRING) {
@@ -1012,6 +1020,14 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2, 3, 4, 5, 6, 7, 8, 9) lxb_url_t *php_uri_parser
10121020
if (status != LXB_STATUS_OK) {
10131021
goto failure;
10141022
}
1023+
} else if (lexbor_base_url->password.data != NULL) {
1024+
zval zv;
1025+
ZVAL_NULL(&zv);
1026+
const zend_result result = php_uri_parser_whatwg_password_write(lexbor_url, &zv, NULL);
1027+
php_uri_parser_whatwg_build_errors(&errors);
1028+
if (result == FAILURE) {
1029+
goto failure;
1030+
}
10151031
}
10161032

10171033
if (Z_TYPE_P(host) == IS_STRING) {
@@ -1037,6 +1053,14 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 2, 3, 4, 5, 6, 7, 8, 9) lxb_url_t *php_uri_parser
10371053
if (status != LXB_STATUS_OK) {
10381054
goto failure;
10391055
}
1056+
} else if (lexbor_base_url->has_port) {
1057+
zval zv;
1058+
ZVAL_NULL(&zv);
1059+
const zend_result result = php_uri_parser_whatwg_port_write(lexbor_url, &zv, NULL);
1060+
php_uri_parser_whatwg_build_errors(&errors);
1061+
if (result == FAILURE) {
1062+
goto failure;
1063+
}
10401064
}
10411065

10421066
if (Z_TYPE_P(path) == IS_STRING && Z_STRLEN_P(path) > 0) {
@@ -1116,12 +1140,6 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(2, 3, 4, 5, 6, 7, 8, 9) lxb_url_t *php_uri_parser_wh
11161140
) {
11171141
lxb_url_parser_clean(&lexbor_parser);
11181142

1119-
if (lexbor_base_url != NULL && Z_TYPE_P(scheme) == IS_STRING && Z_STRLEN_P(scheme) == 0) {
1120-
return php_uri_parser_whatwg_resolve_reference_from_zval(
1121-
lexbor_base_url, scheme, username, password, host, port, path, query, fragment, errors_zv
1122-
);
1123-
}
1124-
11251143
if (Z_TYPE_P(host) == IS_NULL ||
11261144
Z_STRLEN_P(host) == 0 ||
11271145
php_uri_parser_whatwg_get_special_scheme(Z_STR_P(scheme)) == LXB_URL_SCHEMEL_TYPE_FILE
@@ -1142,6 +1160,12 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(2, 3, 4, 5, 6, 7, 8, 9) lxb_url_t *php_uri_parser_wh
11421160
}
11431161
}
11441162

1163+
if (lexbor_base_url != NULL && Z_TYPE_P(scheme) == IS_STRING && Z_STRLEN_P(scheme) == 0) {
1164+
return php_uri_parser_whatwg_resolve_reference_from_zval(
1165+
lexbor_base_url, scheme, username, password, host, port, path, query, fragment, errors_zv
1166+
);
1167+
}
1168+
11451169
lxb_url_t *lexbor_url = lexbor_mraw_calloc(lexbor_parser.mraw, sizeof(*lexbor_url));
11461170
if (lexbor_url == NULL) {
11471171
zend_throw_exception(php_uri_ce_whatwg_invalid_url_exception, "Memory allocation error", 0);

0 commit comments

Comments
 (0)