1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

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
This commit is contained in:
Andre Klapper 2024-06-10 19:12:40 +02:00
parent a83ba95445
commit 10cb252163

View file

@ -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++;
}