From 562d36ef5f9e83dba5e3ca0244f9c4af9e1f7b2b Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 29 Apr 2023 21:53:11 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exceptions to render the Account Creation page Summary: Fix numerous PHP 8.1 "strlen(null)" exceptions which block rendering the initial Account Creation page in a fresh Phorge installation. The strlen() was used in Phabricator to check if a generic value was a non-empty string. For this reason, Phorge adopts phutil_nonempty_string() that checks that. Note: this may highlight other absurd input values that might be worth correcting instead of just ignoring. If your phutil_nonempty_string() throws an exception, just report it to Phorge to evaluate and fix together that specific corner case. Closes T15279 Test Plan: After these code changes the account creation page got displayed (though without CSS and JS). Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: avivey, speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15279 Differential Revision: https://we.phorge.it/D25137 --- .../auth/controller/PhabricatorAuthRegisterController.php | 6 +++--- src/applications/base/controller/PhabricatorController.php | 2 +- src/view/form/control/AphrontFormControl.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/applications/auth/controller/PhabricatorAuthRegisterController.php b/src/applications/auth/controller/PhabricatorAuthRegisterController.php index 9fbf30d092..a71e576476 100644 --- a/src/applications/auth/controller/PhabricatorAuthRegisterController.php +++ b/src/applications/auth/controller/PhabricatorAuthRegisterController.php @@ -18,7 +18,7 @@ final class PhabricatorAuthRegisterController $invite = $this->loadInvite(); $is_setup = false; - if (strlen($account_key)) { + if (phutil_nonempty_string($account_key)) { $result = $this->loadAccountForRegistrationOrLinking($account_key); list($account, $provider, $response) = $result; $is_default = false; @@ -244,9 +244,9 @@ final class PhabricatorAuthRegisterController $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name'); - $e_username = strlen($value_username) ? null : true; + $e_username = phutil_nonempty_string($value_username) ? null : true; $e_realname = $require_real_name ? true : null; - $e_email = strlen($value_email) ? null : true; + $e_email = phutil_nonempty_string($value_email) ? null : true; $e_password = true; $e_captcha = true; diff --git a/src/applications/base/controller/PhabricatorController.php b/src/applications/base/controller/PhabricatorController.php index db9d456094..d1b1fcfc8e 100644 --- a/src/applications/base/controller/PhabricatorController.php +++ b/src/applications/base/controller/PhabricatorController.php @@ -74,7 +74,7 @@ abstract class PhabricatorController extends AphrontController { $session_engine = new PhabricatorAuthSessionEngine(); $phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); - if (strlen($phsid)) { + if (phutil_nonempty_string($phsid)) { $session_user = $session_engine->loadUserForSession( PhabricatorAuthSession::TYPE_WEB, $phsid); diff --git a/src/view/form/control/AphrontFormControl.php b/src/view/form/control/AphrontFormControl.php index 0125fa87b3..d891636230 100644 --- a/src/view/form/control/AphrontFormControl.php +++ b/src/view/form/control/AphrontFormControl.php @@ -172,7 +172,7 @@ abstract class AphrontFormControl extends AphrontView { $this->renderInput()); $error = null; - if (strlen($this->getError())) { + if ($this->getError()) { $error = $this->getError(); if ($error === true) { $error = phutil_tag( @@ -187,7 +187,7 @@ abstract class AphrontFormControl extends AphrontView { } } - if (strlen($this->getLabel())) { + if (phutil_nonempty_string($this->getLabel())) { $label = phutil_tag( 'label', array( @@ -203,7 +203,7 @@ abstract class AphrontFormControl extends AphrontView { $custom_class .= ' aphront-form-control-nolabel'; } - if (strlen($this->getCaption())) { + if (phutil_nonempty_string($this->getCaption())) { $caption = phutil_tag( 'div', array('class' => 'aphront-form-caption'),