1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-19 00:18:50 +02:00

Fix PHP 8.1 "preg_match(null)" exception for missing Content-Type

Summary:
When the `Content-Type` HTTP header is empty or missing, `null` is passed to `preg_match()` which is deprecated behavior since PHP 8.1. Thus only call `preg_match()` when the value is set.

```
ERROR 8192: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at [$HOME/arcanist/src/future/http/status/HTTPFutureHTTPResponseStatus.php:24]
```

Closes T15821

Test Plan: Visit something using `HTTPFutureHTTPResponseStatus`, like, a profile image. No crashes.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15821

Differential Revision: https://we.phorge.it/D25632
This commit is contained in:
Andre Klapper 2024-05-10 12:04:39 +02:00
parent 6718b32a64
commit 7f28d7266f

View file

@ -21,7 +21,8 @@ final class HTTPFutureHTTPResponseStatus extends HTTPFutureResponseStatus {
$content_type = BaseHTTPFuture::getHeader($headers, 'Content-Type');
$match = null;
if (preg_match('/;\s*charset=([^;]+)/', $content_type, $match)) {
if (phutil_nonempty_string($content_type) &&
preg_match('/;\s*charset=([^;]+)/', $content_type, $match)) {
$encoding = trim($match[1], "\"'");
try {
$excerpt = phutil_utf8_convert($excerpt, 'UTF-8', $encoding);