From b4cfe56f03b44615ac9251aed8d74bf13b085051 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 10 Jun 2023 18:40:00 +0200 Subject: [PATCH] Fix PHP 8.1 "ltrim(null)" exception which blocks rendering first Meme comment Summary: Since PHP 8.1, passing a null string to `ltrim(string $string)` is deprecated. Thus first check if After and Below text are not null before trimming. Closes T15379 Test Plan: Applied this change; afterwards several times created a new Pholio mock and added a Meme comment. I could not reproduce the problem anymore (first meme comment in a mock always rendered correctly instead of showing an exception as comment). However, I could not reliably reproduce the problem anyway. - Create a meme without any above/below text - Create a meme with just spaces as above/below text - Create a meme with just above text as "asd", or "0" or a lizard - Create a meme with just below text as "asd", or "0" or a lizard - Create a meme with both above and below texts with "asd", "0" and a lizard and more stuff (doing all 64 combinations) Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15379 Differential Revision: https://we.phorge.it/D25212 --- src/applications/macro/engine/PhabricatorMemeEngine.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/applications/macro/engine/PhabricatorMemeEngine.php b/src/applications/macro/engine/PhabricatorMemeEngine.php index afee0f9b18..e1befc20a2 100644 --- a/src/applications/macro/engine/PhabricatorMemeEngine.php +++ b/src/applications/macro/engine/PhabricatorMemeEngine.php @@ -182,7 +182,8 @@ final class PhabricatorMemeEngine extends Phobject { // changes to the image. $above_text = $this->getAboveText(); $below_text = $this->getBelowText(); - if (!strlen(trim($above_text)) && !strlen(trim($below_text))) { + if (($above_text === null || !phutil_nonempty_string(trim($above_text))) && + ($below_text === null || !phutil_nonempty_string(trim($below_text)))) { return $template_data; }