From 6c692ddbbba858e790751dbb6e1a199dc303b398 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 6 May 2023 04:06:44 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exceptions which block rendering page of a File Summary: `strlen()` was used in Phabricator to check if a generic value is a non-empty string. This behavior is deprecated since PHP 8.1. Phorge adopts `phutil_nonempty_string()` as a replacement. Note: this may highlight other absurd input values that might be worth correcting instead of just ignoring. If phutil_nonempty_string() throws an exception in your instance, report it to Phorge to evaluate and fix that specific corner case. Closes T15341 Test Plan: Applied these four changes and file page at `/F91` finally rendered in web browser. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15341 Differential Revision: https://we.phorge.it/D25186 --- .../files/controller/PhabricatorFileViewController.php | 2 +- .../document/render/PhabricatorDocumentRenderingEngine.php | 4 ++-- src/applications/files/storage/PhabricatorFile.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/applications/files/controller/PhabricatorFileViewController.php b/src/applications/files/controller/PhabricatorFileViewController.php index 389fc66247..2dea0a51ce 100644 --- a/src/applications/files/controller/PhabricatorFileViewController.php +++ b/src/applications/files/controller/PhabricatorFileViewController.php @@ -311,7 +311,7 @@ final class PhabricatorFileViewController extends PhabricatorFileController { $file->getStorageHandle()); $custom_alt = $file->getCustomAltText(); - if (strlen($custom_alt)) { + if (phutil_nonempty_string($custom_alt)) { $finfo->addProperty(pht('Custom Alt Text'), $custom_alt); } diff --git a/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php b/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php index 5a4cb77340..f43689bbba 100644 --- a/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php +++ b/src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php @@ -60,12 +60,12 @@ abstract class PhabricatorDocumentRenderingEngine } $encode_setting = $request->getStr('encode'); - if (strlen($encode_setting)) { + if (phutil_nonempty_string($encode_setting)) { $engine->setEncodingConfiguration($encode_setting); } $highlight_setting = $request->getStr('highlight'); - if (strlen($highlight_setting)) { + if (phutil_nonempty_string($highlight_setting)) { $engine->setHighlightingConfiguration($highlight_setting); } diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php index 355aa2d215..44e35c6b72 100644 --- a/src/applications/files/storage/PhabricatorFile.php +++ b/src/applications/files/storage/PhabricatorFile.php @@ -1278,7 +1278,7 @@ final class PhabricatorFile extends PhabricatorFileDAO public function getAltText() { $alt = $this->getCustomAltText(); - if (strlen($alt)) { + if (phutil_nonempty_string($alt)) { return $alt; }