1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Fix PHP 8.1 "strlen(null)" and "preg_match()" exceptions which block repository creation

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.

Similarly, `preg_match()` does not accept passing `null` as `$subject` parameter since PHP 8.1.

Closes T15337

Test Plan: Applied these four changes and `/diffusion/4/manage/` finally rendered in web browser.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

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

Maniphest Tasks: T15337

Differential Revision: https://we.phorge.it/D25182
This commit is contained in:
Andre Klapper 2023-05-19 17:18:01 +02:00
parent 912a933b02
commit 9f1814f490
4 changed files with 5 additions and 5 deletions

View file

@ -40,7 +40,7 @@ final class DiffusionRepositoryManagePanelsController
} }
$selected = $request->getURIData('panel'); $selected = $request->getURIData('panel');
if (!strlen($selected)) { if (!phutil_nonempty_string($selected)) {
$selected = head_key($panels); $selected = head_key($panels);
} }

View file

@ -43,8 +43,8 @@ final class DiffusionServeController extends DiffusionController {
return null; return null;
} }
$content_type = $request->getHTTPHeader('Content-Type'); $content_type = $request->getHTTPHeader('Content-Type', '');
$user_agent = idx($_SERVER, 'HTTP_USER_AGENT'); $user_agent = idx($_SERVER, 'HTTP_USER_AGENT', '');
$request_type = $request->getHTTPHeader('X-Phabricator-Request-Type'); $request_type = $request->getHTTPHeader('X-Phabricator-Request-Type');
// This may have a "charset" suffix, so only match the prefix. // This may have a "charset" suffix, so only match the prefix.

View file

@ -219,7 +219,7 @@ final class DiffusionRepositoryBasicsManagementPanel
$view->addProperty(pht('Type'), $type); $view->addProperty(pht('Type'), $type);
$callsign = $repository->getCallsign(); $callsign = $repository->getCallsign();
if (!strlen($callsign)) { if (!phutil_nonempty_string($callsign)) {
$callsign = phutil_tag('em', array(), pht('No Callsign')); $callsign = phutil_tag('em', array(), pht('No Callsign'));
} }
$view->addProperty(pht('Callsign'), $callsign); $view->addProperty(pht('Callsign'), $callsign);

View file

@ -50,7 +50,7 @@ final class PhabricatorRepositoryEditor
// If the repository does not have a local path yet, assign it one based // If the repository does not have a local path yet, assign it one based
// on its ID. We can't do this earlier because we won't have an ID yet. // on its ID. We can't do this earlier because we won't have an ID yet.
$local_path = $object->getLocalPath(); $local_path = $object->getLocalPath();
if (!strlen($local_path)) { if (!phutil_nonempty_string($local_path)) {
$local_key = 'repository.default-local-path'; $local_key = 'repository.default-local-path';
$local_root = PhabricatorEnv::getEnvConfig($local_key); $local_root = PhabricatorEnv::getEnvConfig($local_key);