From a9822a37aa5ac6a700b7c3e998027393bf831be2 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 1 Apr 2022 12:06:38 -0700 Subject: [PATCH] Fix a PHP 8.1 unit test failure in Projects Summary: Ref T13588. This field may be "null" (and is probably never the empty string, but that's a more ambitious fix). Test Plan: Ran unit tests, got a pass. Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21752 --- .../herald/storage/transcript/HeraldTranscript.php | 4 ++++ .../project/__tests__/PhabricatorProjectCoreTestCase.php | 2 +- src/applications/project/storage/PhabricatorProject.php | 6 ++++-- .../transactions/editengine/PhabricatorEditEngine.php | 4 +++- .../storage/PhabricatorEditEngineConfiguration.php | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/applications/herald/storage/transcript/HeraldTranscript.php b/src/applications/herald/storage/transcript/HeraldTranscript.php index 9539d4653d..f977c44485 100644 --- a/src/applications/herald/storage/transcript/HeraldTranscript.php +++ b/src/applications/herald/storage/transcript/HeraldTranscript.php @@ -66,6 +66,10 @@ final class HeraldTranscript extends HeraldDAO } private static function combineXHeraldRulesHeaders($u, $v) { + if ($u === null) { + return $v; + } + $u = preg_split('/[, ]+/', $u); $v = preg_split('/[, ]+/', $v); diff --git a/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php b/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php index a31bf8853c..e3a138c702 100644 --- a/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php +++ b/src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php @@ -1435,7 +1435,7 @@ final class PhabricatorProjectCoreTestCase extends PhabricatorTestCase { $task = ManiphestTask::initializeNewTask($viewer); - if (!strlen($name)) { + if ($name === null || $name === '') { $name = pht('Test Task'); } diff --git a/src/applications/project/storage/PhabricatorProject.php b/src/applications/project/storage/PhabricatorProject.php index 860d6e1749..6aebc954df 100644 --- a/src/applications/project/storage/PhabricatorProject.php +++ b/src/applications/project/storage/PhabricatorProject.php @@ -407,11 +407,13 @@ final class PhabricatorProject extends PhabricatorProjectDAO $this->setMailKey(Filesystem::readRandomCharacters(20)); } - if (!strlen($this->getPHID())) { + $phid = $this->getPHID(); + if ($phid === null || $phid === '') { $this->setPHID($this->generatePHID()); } - if (!strlen($this->getProjectPathKey())) { + $path_key = $this->getProjectPathKey(); + if ($path_key === null || $path_key === '') { $hash = PhabricatorHash::digestForIndex($this->getPHID()); $hash = substr($hash, 0, 4); $this->setProjectPathKey($hash); diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php index ea1d7ed773..d0bb1972b6 100644 --- a/src/applications/transactions/editengine/PhabricatorEditEngine.php +++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php @@ -474,7 +474,9 @@ abstract class PhabricatorEditEngine ->setIsDefault(true) ->setIsEdit(true); - if (!strlen($first->getName())) { + $first_name = $first->getName(); + + if ($first_name === null || $first_name === '') { $first->setName($this->getObjectCreateShortText()); } } else { diff --git a/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php b/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php index b1919a0ee0..ae55b9a4bf 100644 --- a/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php +++ b/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php @@ -185,7 +185,7 @@ final class PhabricatorEditEngineConfiguration $fields = $this->reorderFields($fields); $preamble = $this->getPreamble(); - if (strlen($preamble)) { + if ($preamble !== null && strlen($preamble)) { $fields = array( 'config.preamble' => id(new PhabricatorInstructionsEditField()) ->setKey('config.preamble')