1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Fix PHP 8.1 "strlen(null)" exceptions handling empty comment metadata in PhabricatorEditEngine

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.

```
ERROR 8192: strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/transactions/editengine/PhabricatorEditEngine.php:1923]
```

```
ERROR 8192: strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/transactions/editengine/PhabricatorEditEngine.php:2023]
```

Closes T15864

Test Plan: See steps in https://we.phorge.it/T15864

Reviewers: O1 Blessed Committers, speck

Reviewed By: O1 Blessed Committers, speck

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15864

Differential Revision: https://we.phorge.it/D25699
This commit is contained in:
Andre Klapper 2024-06-24 15:14:27 +02:00
parent 68762e8204
commit 5a9cf81ae5

View file

@ -1920,7 +1920,7 @@ abstract class PhabricatorEditEngine
$comment_text = $request->getStr('comment');
$comment_metadata = $request->getStr('comment_metadata');
if (strlen($comment_metadata)) {
if (phutil_nonempty_string($comment_metadata)) {
$comment_metadata = phutil_json_decode($comment_metadata);
}
@ -2020,7 +2020,7 @@ abstract class PhabricatorEditEngine
$xactions[] = $xaction;
}
if (strlen($comment_text) || !$xactions) {
if (phutil_nonempty_string($comment_text) || !$xactions) {
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->setMetadataValue('remarkup.control', $comment_metadata)