Page MenuHomePhorge

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

Authored by aklapper on Apr 22 2023, 13:17.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 03:55
Unknown Object (File)
Wed, Apr 10, 18:07
Unknown Object (File)
Mon, Apr 8, 05:36
Unknown Object (File)
Sat, Apr 6, 17:28
Unknown Object (File)
Mon, Apr 1, 05:00
Unknown Object (File)
Mon, Apr 1, 01:16
Unknown Object (File)
Mon, Apr 1, 01:16
Unknown Object (File)
Mon, Apr 1, 01:16

Details

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

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

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

src/applications/config/check/PhabricatorDaemonsSetupCheck.php
56

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

src/applications/files/view/PhabricatorGlobalUploadTargetView.php
70

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

Known usages:

./src/applications/xhprof/query/PhabricatorXHProfSampleSearchEngine.php:        ->setHintText("\xE2\x87\xAA ".pht('Drop .xhprof Files to Import'))
./src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php:        ->setHintText("\xE2\x87\xAA ".pht('Drop .ics Files to Import'))
src/applications/search/engine/PhabricatorProfileMenuEngine.php
1311

๐Ÿ‘€ This should be double-checked

Sometime Phabricator handles IDs as integers and - if this happens here - phutil will throw.

src/applications/search/engine/PhabricatorProfileMenuItemView.php
143

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

179

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

Example usage:

->setTooltip(pht('Silent Edit'))
src/view/page/menu/PhabricatorMainMenuView.php
336

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

Context:

./src/applications/config/custom/PhabricatorCustomLogoConfigType.php
public static function getLogoWordmark() {
  $logo = PhabricatorEnv::getEnvConfig('ui.logo');
  return idx($logo, 'wordmarkText');
}
src/view/phui/PHUIObjectItemView.php
662โ€“664

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

src/applications/home/menuitem/PhabricatorHomeLauncherProfileMenuItem.php
34

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

Context input:

src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
public function getMenuItemProperty($key, $default = null) {
  return idx($this->menuItemProperties, $key, $default);
}
src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
120

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

Context input:

src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
private function getName(
  PhabricatorProfileMenuItemConfiguration $config) {
  return $config->getMenuItemProperty('name');
}
src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
public function getMenuItemProperty($key, $default = null) {
  return idx($this->menuItemProperties, $key, $default);
}
src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php
74

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

Context input:

src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php
private function getName(
  PhabricatorProfileMenuItemConfiguration $config) {
  return $config->getMenuItemProperty('name');
}
src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
public function getMenuItemProperty($key, $default = null) {
  return idx($this->menuItemProperties, $key, $default);
}
src/applications/search/menuitem/PhabricatorManageProfileMenuItem.php
34

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

Context input:

src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
public function getMenuItemProperty($key, $default = null) {
  return idx($this->menuItemProperties, $key, $default);
}
src/view/page/PhabricatorStandardPageView.php
191

โœ… OK since the expected input domain is NULL (default) or a string. The phutil will throw for alien types, and it's OK.

valerio.bozzolan added inline comments.
src/applications/search/engine/PhabricatorProfileMenuEngine.php
1311

It seems to me that $item_id comes from buildResponse() from the same class, from this line:

$item_id = $request->getURIData('itemID');

So:

public function getURIData($key, $default = null) {
  return idx($this->uriData, $key, $default);
}

And the uriData comes for example from:

$request->setURIMap(
  array(
    'id' => head($must_sign_docs)->getID(),
  ));

At this point I can 99.9999% say that ID is just a string.

If a related problem will be raised, we can surly adopt instead phutil_nonempty_scalar in the future.

src/view/phui/PHUIObjectItemListView.php
123

This is the most risky to me.

โœ… Anyway I've done a series of spot checks and it seems everything that call PHUIObjectItemListView#setHeader() is always assuming a string or NULL (like PhabricatorEditEngine#getSummaryHeader() etc.)

If we will encounter issues we can adopt phutil_nonempty_scalar() instead.

This revision is now accepted and ready to land.Apr 27 2023, 10:13

I can confirm that I successfully opened the homepage of Phorge after merging D25132 and D25137 locally ๐ŸŽ‰ Thanks

src/view/phui/PHUIObjectItemView.php
662โ€“664
IMPORTANT: This can also be a PhutilURI object. So they should be phutil_nonempty_stringlike().

Steps to reproduce: Create Dashboard, add Panel: Call to phutil_nonempty_string() expected null or a string, got: PhutilURI..