1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.5'

* PHP-8.5:
  Fix the distinction between missing and empty username/password for RFC3986 URIs (#20335)
This commit is contained in:
Máté Kocsis
2025-11-02 23:34:54 +01:00
4 changed files with 107 additions and 2 deletions

View File

@@ -0,0 +1,35 @@
--TEST--
Test Uri\Rfc3986\Uri parsing - userinfo - empty
--EXTENSIONS--
uri
--FILE--
<?php
$uri = Uri\Rfc3986\Uri::parse("https://@example.com");
var_dump($uri);
var_dump($uri->toRawString());
var_dump($uri->toString());
?>
--EXPECTF--
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
string(0) ""
["password"]=>
string(0) ""
["host"]=>
string(11) "example.com"
["port"]=>
NULL
["path"]=>
string(0) ""
["query"]=>
NULL
["fragment"]=>
NULL
}
string(20) "https://@example.com"
string(20) "https://@example.com"

View File

@@ -0,0 +1,35 @@
--TEST--
Test Uri\Rfc3986\Uri parsing - userinfo - only password
--EXTENSIONS--
uri
--FILE--
<?php
$uri = Uri\Rfc3986\Uri::parse("https://:pass@example.com");
var_dump($uri);
var_dump($uri->toRawString());
var_dump($uri->toString());
?>
--EXPECTF--
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
string(0) ""
["password"]=>
string(4) "pass"
["host"]=>
string(11) "example.com"
["port"]=>
NULL
["path"]=>
string(0) ""
["query"]=>
NULL
["fragment"]=>
NULL
}
string(25) "https://:pass@example.com"
string(25) "https://:pass@example.com"

View File

@@ -0,0 +1,35 @@
--TEST--
Test Uri\Rfc3986\Uri parsing - userinfo - only username
--EXTENSIONS--
uri
--FILE--
<?php
$uri = Uri\Rfc3986\Uri::parse("https://user:@example.com");
var_dump($uri);
var_dump($uri->toRawString());
var_dump($uri->toString());
?>
--EXPECTF--
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
string(4) "user"
["password"]=>
string(0) ""
["host"]=>
string(11) "example.com"
["port"]=>
NULL
["path"]=>
string(0) ""
["query"]=>
NULL
["fragment"]=>
NULL
}
string(25) "https://user:@example.com"
string(25) "https://user:@example.com"

View File

@@ -202,7 +202,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_username_read(v
} else if (c != NULL && c - uriparser_uri->userInfo.first > 0) {
ZVAL_STRINGL(retval, uriparser_uri->userInfo.first, c - uriparser_uri->userInfo.first);
} else {
ZVAL_NULL(retval);
ZVAL_EMPTY_STRING(retval);
}
} else {
ZVAL_NULL(retval);
@@ -221,7 +221,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_password_read(v
if (c != NULL && uriparser_uri->userInfo.afterLast - c - 1 > 0) {
ZVAL_STRINGL(retval, c + 1, uriparser_uri->userInfo.afterLast - c - 1);
} else {
ZVAL_NULL(retval);
ZVAL_EMPTY_STRING(retval);
}
} else {
ZVAL_NULL(retval);