Skip to content

Commit 6ef4c13

Browse files
committed
Update uriparser + verify behavior
1 parent 731137b commit 6ef4c13

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

ext/uri/tests/026_userinfo.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ var_dump($uri3->getUserInfo());
1616
var_dump($uri4->getUserInfo());
1717
var_dump($uri4->getRawUserInfo());
1818

19+
$uri1 = Uri\Rfc3986\Uri::parse("/foo");
20+
$uri2 = $uri1->withUserInfo(null);
21+
var_dump($uri2->getPort());
22+
1923
try {
2024
$uri4->withUserInfo("u:s/r");
2125
} catch (Uri\InvalidUriException $e) {
@@ -35,6 +39,7 @@ string(4) "user"
3539
NULL
3640
string(11) "us%2Fr:pass"
3741
string(13) "%75s%2Fr:pass"
42+
NULL
3843
The specified userinfo is malformed
3944
NULL
4045
string(9) "user:pass"

ext/uri/tests/027.phpt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ var_dump($uri1->getPort());
2626
var_dump($uri2->getPort());
2727

2828
$uri1 = Uri\Rfc3986\Uri::parse("/foo");
29-
30-
try {
31-
$uri1->withPort(null); // TODO should not throw
32-
} catch (Uri\InvalidUriException $e) {
33-
echo $e->getMessage() . "\n";
34-
}
29+
$uri2 = $uri1->withPort(null);
30+
var_dump($uri2->getPort());
3531

3632
try {
3733
$uri1->withPort(1);
@@ -68,7 +64,7 @@ int(443)
6864
int(8080)
6965
NULL
7066
int(80)
71-
The specified port is malformed
67+
NULL
7268
The specified port is malformed
7369
int(8080)
7470
int(22)

ext/uri/uriparser/src/UriSetPort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int URI_FUNC(SetPortTextMm)(URI_TYPE(Uri) * uri,
120120
/* The RFC 3986 grammar reads:
121121
* authority = [ userinfo "@" ] host [ ":" port ]
122122
* So no port without a host. */
123-
if (URI_FUNC(HasHost)(uri) == URI_FALSE) {
123+
if ((first != NULL) && (URI_FUNC(HasHost)(uri) == URI_FALSE)) {
124124
return URI_ERROR_SETPORT_HOST_NOT_SET;
125125
}
126126

ext/uri/uriparser/src/UriSetUserInfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ int URI_FUNC(SetUserInfoMm)(URI_TYPE(Uri) * uri,
247247
/* The RFC 3986 grammar reads:
248248
* authority = [ userinfo "@" ] host [ ":" port ]
249249
* So no user info without a host. */
250-
if (URI_FUNC(HasHost)(uri) == URI_FALSE) {
250+
if ((first != NULL) && (URI_FUNC(HasHost)(uri) == URI_FALSE)) {
251251
return URI_ERROR_SETUSERINFO_HOST_NOT_SET;
252252
}
253253

0 commit comments

Comments
 (0)