bug #40964 [HttpFoundation] Fixes for PHP 8.1 deprecations (jrmajor)
This PR was merged into the 4.4 branch.
Discussion
----------
[HttpFoundation] Fixes for PHP 8.1 deprecations
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
Fixes passing `null` to non-nullable arguments.
Commits
-------
10be072b2b
[HttpFoundation] Fixes for PHP 8.1 deprecations
This commit is contained in:
commit
a88c7fa0eb
@ -292,7 +292,7 @@ class Request
|
|||||||
{
|
{
|
||||||
$request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
|
$request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
|
||||||
|
|
||||||
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
|
if (0 === strpos($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded')
|
||||||
&& \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
|
&& \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
|
||||||
) {
|
) {
|
||||||
parse_str($request->getContent(), $data);
|
parse_str($request->getContent(), $data);
|
||||||
@ -1391,7 +1391,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function getContentType()
|
public function getContentType()
|
||||||
{
|
{
|
||||||
return $this->getFormat($this->headers->get('CONTENT_TYPE'));
|
return $this->getFormat($this->headers->get('CONTENT_TYPE', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1564,7 +1564,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function getETags()
|
public function getETags()
|
||||||
{
|
{
|
||||||
return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), -1, \PREG_SPLIT_NO_EMPTY);
|
return preg_split('/\s*,\s*/', $this->headers->get('if_none_match', ''), -1, \PREG_SPLIT_NO_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1790,13 +1790,13 @@ class Request
|
|||||||
*/
|
*/
|
||||||
protected function prepareBaseUrl()
|
protected function prepareBaseUrl()
|
||||||
{
|
{
|
||||||
$filename = basename($this->server->get('SCRIPT_FILENAME'));
|
$filename = basename($this->server->get('SCRIPT_FILENAME', ''));
|
||||||
|
|
||||||
if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
|
if (basename($this->server->get('SCRIPT_NAME', '')) === $filename) {
|
||||||
$baseUrl = $this->server->get('SCRIPT_NAME');
|
$baseUrl = $this->server->get('SCRIPT_NAME');
|
||||||
} elseif (basename($this->server->get('PHP_SELF')) === $filename) {
|
} elseif (basename($this->server->get('PHP_SELF', '')) === $filename) {
|
||||||
$baseUrl = $this->server->get('PHP_SELF');
|
$baseUrl = $this->server->get('PHP_SELF');
|
||||||
} elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
|
} elseif (basename($this->server->get('ORIG_SCRIPT_NAME', '')) === $filename) {
|
||||||
$baseUrl = $this->server->get('ORIG_SCRIPT_NAME'); // 1and1 shared hosting compatibility
|
$baseUrl = $this->server->get('ORIG_SCRIPT_NAME'); // 1and1 shared hosting compatibility
|
||||||
} else {
|
} else {
|
||||||
// Backtrack up the script_filename to find the portion matching
|
// Backtrack up the script_filename to find the portion matching
|
||||||
@ -1836,7 +1836,7 @@ class Request
|
|||||||
$truncatedRequestUri = substr($requestUri, 0, $pos);
|
$truncatedRequestUri = substr($requestUri, 0, $pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
$basename = basename($baseUrl);
|
$basename = basename($baseUrl ?? '');
|
||||||
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
|
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
|
||||||
// no match whatsoever; set it blank
|
// no match whatsoever; set it blank
|
||||||
return '';
|
return '';
|
||||||
@ -1987,7 +1987,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function isFromTrustedProxy()
|
public function isFromTrustedProxy()
|
||||||
{
|
{
|
||||||
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
|
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR', ''), self::$trustedProxies);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTrustedValues(int $type, string $ip = null): array
|
private function getTrustedValues(int $type, string $ip = null): array
|
||||||
|
@ -9,4 +9,4 @@ $str = '?*():@&+$/%#[]';
|
|||||||
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true, null));
|
$r->headers->setCookie(new Cookie($str, $str, 0, '/', null, false, false, true, null));
|
||||||
$r->sendHeaders();
|
$r->sendHeaders();
|
||||||
|
|
||||||
setrawcookie($str, $str, 0, '/', null, false, false);
|
setrawcookie($str, $str, 0, '/', '', false, false);
|
||||||
|
@ -446,7 +446,7 @@ class RequestTest extends TestCase
|
|||||||
public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat()
|
public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat()
|
||||||
{
|
{
|
||||||
return array_merge(
|
return array_merge(
|
||||||
[[null, [null, 'unexistent-mime-type']]],
|
[[null, ['unexistent-mime-type']]],
|
||||||
$this->getFormatToMimeTypeMapProvider()
|
$this->getFormatToMimeTypeMapProvider()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user