From 10cb2521630aa333b76ff35634b14a793db85f79 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 10 Jun 2024 19:12:40 +0200 Subject: [PATCH] Fix PHP 8.1 exceptions importing ICS file without attendee names 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. Passing `null` to `preg_match()` is deprecated behavior since PHP 8.1. Thus only call `preg_match()` when the value is set. 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. ``` ERROR 8192: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/calendar/import/PhabricatorCalendarImportEngine.php:238] ``` ``` ERROR 8192: strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/calendar/import/PhabricatorCalendarImportEngine.php:245] ``` Closes T15852 Test Plan: Import an ICS file which lists attendees without a name but only with an email address into the calendar via http://phorge.localhost/calendar/import/ > "Import Events" > "Import .ics File" Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15852 Differential Revision: https://we.phorge.it/D25686 --- .../calendar/import/PhabricatorCalendarImportEngine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php index 626757c61d..33809f1516 100644 --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -235,14 +235,14 @@ abstract class PhabricatorCalendarImportEngine // We avoid disclosing email addresses to be consistent with the rest // of the product. $name = $attendee->getName(); - if (preg_match('/@/', $name)) { + if (phutil_nonempty_string($name) && preg_match('/@/', $name)) { $name = new PhutilEmailAddress($name); $name = $name->getDisplayName(); } // If we don't have a name or the name still looks like it's an // email address, give them a dummy placeholder name. - if (!strlen($name) || preg_match('/@/', $name)) { + if (!phutil_nonempty_string($name) || preg_match('/@/', $name)) { $name = pht('Private User %d', $private_index); $private_index++; }