1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Fix numerous PHP 8.1 "strlen(null)" exceptions preventing homepage to display

Summary:
Fix numerous PHP 8.1 RuntimeExceptions caused by the deprecation of strlen(null).

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 T15264

Test Plan: Phorge homepage is displayed on PHP 8.1 after applying these changes

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15264

Differential Revision: https://we.phorge.it/D25132
This commit is contained in:
Andre Klapper 2023-04-27 14:07:51 +02:00
parent f3b3741316
commit b56d86e48d
12 changed files with 14 additions and 13 deletions

View file

@ -53,7 +53,7 @@ final class PhabricatorDaemonsSetupCheck extends PhabricatorSetupCheck {
} }
$expect_user = PhabricatorEnv::getEnvConfig('phd.user'); $expect_user = PhabricatorEnv::getEnvConfig('phd.user');
if (strlen($expect_user)) { if (phutil_nonempty_string($expect_user)) {
try { try {
$all_daemons = id(new PhabricatorDaemonLogQuery()) $all_daemons = id(new PhabricatorDaemonLogQuery())

View file

@ -67,7 +67,7 @@ final class PhabricatorGlobalUploadTargetView extends AphrontView {
require_celerity_resource('global-drag-and-drop-css'); require_celerity_resource('global-drag-and-drop-css');
$hint_text = $this->getHintText(); $hint_text = $this->getHintText();
if (!strlen($hint_text)) { if (!phutil_nonempty_string($hint_text)) {
$hint_text = "\xE2\x87\xAA ".pht('Drop Files to Upload'); $hint_text = "\xE2\x87\xAA ".pht('Drop Files to Upload');
} }

View file

@ -31,7 +31,7 @@ final class PhabricatorHomeLauncherProfileMenuItem
PhabricatorProfileMenuItemConfiguration $config) { PhabricatorProfileMenuItemConfiguration $config) {
$name = $config->getMenuItemProperty('name'); $name = $config->getMenuItemProperty('name');
if (strlen($name)) { if (phutil_nonempty_string($name)) {
return $name; return $name;
} }

View file

@ -1308,7 +1308,7 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
// render the default view instead. // render the default view instead.
$selected_view = null; $selected_view = null;
if (strlen($item_id)) { if (phutil_nonempty_string($item_id)) {
$item_views = $view_list->getViewsWithItemIdentifier($item_id); $item_views = $view_list->getViewsWithItemIdentifier($item_id);
if ($item_views) { if ($item_views) {
$selected_view = head($item_views); $selected_view = head($item_views);

View file

@ -140,7 +140,7 @@ final class PhabricatorProfileMenuItemView
->setName($this->getName()); ->setName($this->getName());
$uri = $this->getURI(); $uri = $this->getURI();
if (strlen($uri)) { if (phutil_nonempty_string($uri)) {
if ($this->getIsExternalLink()) { if ($this->getIsExternalLink()) {
if (!PhabricatorEnv::isValidURIForLink($uri)) { if (!PhabricatorEnv::isValidURIForLink($uri)) {
$uri = '#'; $uri = '#';
@ -176,7 +176,7 @@ final class PhabricatorProfileMenuItemView
} }
$tooltip = $this->getTooltip(); $tooltip = $this->getTooltip();
if (strlen($tooltip)) { if (phutil_nonempty_string($tooltip)) {
$view->setTooltip($tooltip); $view->setTooltip($tooltip);
} }

View file

@ -117,7 +117,7 @@ final class PhabricatorDashboardProfileMenuItem
return pht('Archived Dashboard'); return pht('Archived Dashboard');
} }
if (strlen($this->getName($config))) { if (phutil_nonempty_string($this->getName($config))) {
return $this->getName($config); return $this->getName($config);
} else { } else {
return $dashboard->getName(); return $dashboard->getName();

View file

@ -71,7 +71,7 @@ final class PhabricatorEditEngineProfileMenuItem
if (!$form) { if (!$form) {
return pht('(Restricted/Invalid Form)'); return pht('(Restricted/Invalid Form)');
} }
if (strlen($this->getName($config))) { if (phutil_nonempty_string($this->getName($config))) {
return $this->getName($config); return $this->getName($config);
} else { } else {
return $form->getName(); return $form->getName();

View file

@ -31,7 +31,7 @@ final class PhabricatorManageProfileMenuItem
PhabricatorProfileMenuItemConfiguration $config) { PhabricatorProfileMenuItemConfiguration $config) {
$name = $config->getMenuItemProperty('name'); $name = $config->getMenuItemProperty('name');
if (strlen($name)) { if (phutil_nonempty_string($name)) {
return $name; return $name;
} }

View file

@ -188,7 +188,7 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
} }
} }
if (strlen($prefix)) { if (phutil_nonempty_string($prefix)) {
$title = $prefix.' '.$title; $title = $prefix.' '.$title;
} }

View file

@ -333,7 +333,7 @@ final class PhabricatorMainMenuView extends AphrontView {
$wordmark_text = PhabricatorCustomLogoConfigType::getLogoWordmark(); $wordmark_text = PhabricatorCustomLogoConfigType::getLogoWordmark();
if (!strlen($wordmark_text)) { if (!phutil_nonempty_string($wordmark_text)) {
$wordmark_text = PlatformSymbols::getPlatformServerName(); $wordmark_text = PlatformSymbols::getPlatformServerName();
} }

View file

@ -120,7 +120,7 @@ final class PHUIObjectItemListView extends AphrontTagView {
require_celerity_resource('phui-oi-color-css'); require_celerity_resource('phui-oi-color-css');
$header = null; $header = null;
if (strlen($this->header)) { if (phutil_nonempty_string($this->header)) {
$header = phutil_tag( $header = phutil_tag(
'h1', 'h1',
array( array(

View file

@ -659,7 +659,8 @@ final class PHUIObjectItemView extends AphrontTagView {
$this->getImageIcon()); $this->getImageIcon());
} }
if ($image && (strlen($this->href) || strlen($this->imageHref))) { if ($image && (phutil_nonempty_string($this->href) ||
phutil_nonempty_string($this->imageHref))) {
$image_href = ($this->imageHref) ? $this->imageHref : $this->href; $image_href = ($this->imageHref) ? $this->imageHref : $this->href;
$image = phutil_tag( $image = phutil_tag(
'a', 'a',