From 7f28d7266f81985096219a11b949561d70f052e4 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Fri, 10 May 2024 12:04:39 +0200 Subject: [PATCH] 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 --- src/future/http/status/HTTPFutureHTTPResponseStatus.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/future/http/status/HTTPFutureHTTPResponseStatus.php b/src/future/http/status/HTTPFutureHTTPResponseStatus.php index 469f9a0c..44636dca 100644 --- a/src/future/http/status/HTTPFutureHTTPResponseStatus.php +++ b/src/future/http/status/HTTPFutureHTTPResponseStatus.php @@ -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);