1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-16 15:28:48 +02:00

PHP 8.1: fixes for strlen() not accepting NULL anymore, part 2

Summary:
This is a fix for PHP 8.1 deprecation of strlen(NULL), for these Phorge components:

- scripts
- aphront
- project

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 T15223
Ref T15190
Ref T15064

Test Plan: - check with your big eyes that there are no obvious typos

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15223, T15190, T15064

Differential Revision: https://we.phorge.it/D25105
This commit is contained in:
Valerio Bozzolan 2023-04-01 15:19:43 +02:00
parent d25d630fe5
commit 96ae4ba13a
17 changed files with 27 additions and 27 deletions

View file

@ -119,7 +119,7 @@ if ($is_svnrevprop) {
exit($err);
} else if ($repository->isGit() || $repository->isHg()) {
$username = getenv(DiffusionCommitHookEngine::ENV_USER);
if (!strlen($username)) {
if (!phutil_nonempty_string($username)) {
throw new Exception(
pht(
'No Direct Pushes: You are pushing directly to a hosted repository. '.
@ -181,17 +181,17 @@ $engine->setStdin($stdin);
$engine->setOriginalArgv(array_slice($argv, 2));
$remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS);
if (strlen($remote_address)) {
if (phutil_nonempty_string($remote_address)) {
$engine->setRemoteAddress($remote_address);
}
$remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL);
if (strlen($remote_protocol)) {
if (phutil_nonempty_string($remote_protocol)) {
$engine->setRemoteProtocol($remote_protocol);
}
$request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST);
if (strlen($request_identifier)) {
if (phutil_nonempty_string($request_identifier)) {
$engine->setRequestIdentifier($request_identifier);
}

View file

@ -36,7 +36,7 @@ $authstruct_raw = $cache->getKey($authstruct_key);
$authstruct = null;
if (strlen($authstruct_raw)) {
if (phutil_nonempty_string($authstruct_raw)) {
try {
$authstruct = phutil_json_decode($authstruct_raw);
} catch (Exception $ex) {
@ -82,13 +82,13 @@ if ($authstruct === null) {
// Strip out newlines and other nonsense from the key type and key body.
$type = $ssh_key->getKeyType();
$type = preg_replace('@[\x00-\x20]+@', '', $type);
if (!strlen($type)) {
if (!phutil_nonempty_string($type)) {
continue;
}
$key = $ssh_key->getKeyBody();
$key = preg_replace('@[\x00-\x20]+@', '', $key);
if (!strlen($key)) {
if (!phutil_nonempty_string($key)) {
continue;
}
@ -135,7 +135,7 @@ foreach ($authstruct['keys'] as $key_struct) {
$cmd = csprintf('%s %Ls', $bin, $key_argv);
if (strlen($instance)) {
if (phutil_nonempty_string($instance)) {
$cmd = csprintf('PHABRICATOR_INSTANCE=%s %C', $instance, $cmd);
}

View file

@ -103,7 +103,7 @@ try {
'--phabricator-ssh-device',
$user_name,
$device_name));
} else if (strlen($user_name)) {
} else if (phutil_nonempty_string($user_name)) {
$user = id(new PhabricatorPeopleQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withUsernames(array($user_name))
@ -117,7 +117,7 @@ try {
id(new PhabricatorAuthSessionEngine())
->willServeRequestForUser($user);
} else if (strlen($device_name)) {
} else if (phutil_nonempty_string($device_name)) {
if (!$remote_address) {
throw new Exception(
pht(

View file

@ -39,7 +39,7 @@ $data = array();
$futures = array();
foreach (explode("\n", trim($input)) as $file) {
if (!strlen($file)) {
if (!phutil_nonempty_string($file)) {
continue;
}

View file

@ -27,7 +27,7 @@ $data = array();
$futures = array();
foreach (explode("\n", trim($input)) as $file) {
if (!strlen($file)) {
if (!phutil_nonempty_string($file)) {
continue;
}

View file

@ -66,7 +66,7 @@ final class AphrontRequest extends Phobject {
}
public static function parseURILineRange($range, $limit) {
if (!strlen($range)) {
if (!phutil_nonempty_string($range)) {
return null;
}
@ -234,7 +234,7 @@ final class AphrontRequest extends Phobject {
$raw_data = phutil_string_cast($this->requestData[$name]);
$raw_data = trim($raw_data);
if (!strlen($raw_data)) {
if (!phutil_nonempty_string($raw_data)) {
return $default;
}
@ -499,7 +499,7 @@ final class AphrontRequest extends Phobject {
// domain is. This makes setup easier, and we'll tell administrators to
// configure a base domain during the setup process.
$base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri');
if (!strlen($base_uri)) {
if (!phutil_nonempty_string($base_uri)) {
return new PhutilURI('http://'.$host.'/');
}
@ -956,7 +956,7 @@ final class AphrontRequest extends Phobject {
$submit_cookie = PhabricatorCookies::COOKIE_SUBMIT;
$submit_key = $this->getCookie($submit_cookie);
if (strlen($submit_key)) {
if (phutil_nonempty_string($submit_key)) {
$this->clearCookie($submit_cookie);
$this->submitKey = $submit_key;
}

View file

@ -823,7 +823,7 @@ final class AphrontApplicationConfiguration
$raw_input = PhabricatorStartup::getRawInput();
$parser = new PhutilQueryStringParser();
if (strlen($raw_input)) {
if (phutil_nonempty_string($raw_input)) {
$content_type = idx($_SERVER, 'CONTENT_TYPE');
$is_multipart = preg_match('@^multipart/form-data@i', $content_type);
if ($is_multipart) {

View file

@ -64,7 +64,7 @@ final class AphrontAjaxResponse extends AphrontResponse {
if ($viewer) {
$postprocessor_key = $viewer->getUserSetting(
PhabricatorAccessibilitySetting::SETTINGKEY);
if (strlen($postprocessor_key)) {
if (phutil_nonempty_string($postprocessor_key)) {
$response->setPostprocessorKey($postprocessor_key);
}
}

View file

@ -19,7 +19,7 @@ final class AphrontFileResponse extends AphrontResponse {
}
public function setDownload($download) {
if (!strlen($download)) {
if (!phutil_nonempty_string($download)) {
$download = 'untitled';
}
$this->download = $download;

View file

@ -21,7 +21,7 @@ final class AphrontWebpageResponse extends AphrontHTMLResponse {
public function buildResponseString() {
$unexpected_output = $this->getUnexpectedOutput();
if (strlen($unexpected_output)) {
if (phutil_nonempty_string($unexpected_output)) {
$style = array(
'background: linear-gradient(180deg, #eeddff, #ddbbff);',
'white-space: pre-wrap;',

View file

@ -8,7 +8,7 @@ final class AphrontPHPHTTPSink extends AphrontHTTPSink {
protected function emitHTTPStatus($code, $message = '') {
if ($code != 200) {
$header = "HTTP/1.0 {$code}";
if (strlen($message)) {
if (phutil_nonempty_string($message)) {
$header .= " {$message}";
}
header($header);

View file

@ -15,7 +15,7 @@ abstract class AphrontSite extends Phobject {
protected function isHostMatch($host, array $uris) {
foreach ($uris as $uri) {
if (!strlen($uri)) {
if (!phutil_nonempty_string($uri)) {
continue;
}

View file

@ -14,7 +14,7 @@ final class PhabricatorPlatformSite extends PhabricatorSite {
// If no base URI has been configured yet, match this site so the user
// can follow setup instructions.
$base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri');
if (!strlen($base_uri)) {
if (!phutil_nonempty_string($base_uri)) {
return new PhabricatorPlatformSite();
}

View file

@ -14,7 +14,7 @@ final class PhabricatorResourceSite extends PhabricatorSite {
$host = $request->getHost();
$uri = PhabricatorEnv::getEnvConfig('security.alternate-file-domain');
if (!strlen($uri)) {
if (!phutil_nonempty_string($uri)) {
return null;
}

View file

@ -14,7 +14,7 @@ final class PhabricatorShortSite extends PhabricatorSite {
$host = $request->getHost();
$uri = PhabricatorEnv::getEnvConfig('phurl.short-uri');
if (!strlen($uri)) {
if (!phutil_nonempty_string($uri)) {
return null;
}

View file

@ -43,7 +43,7 @@ final class PhabricatorProjectProjectPHIDType extends PhabricatorPHIDType {
$handle->setName($name);
if (strlen($slug)) {
if (phutil_nonempty_string($slug)) {
$handle->setObjectName('#'.$slug);
$handle->setMailStampName('#'.$slug);
$handle->setURI("/tag/{$slug}/");

View file

@ -21,7 +21,7 @@ function preamble_trust_x_forwarded_for_header($layers = 1) {
}
$forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (!strlen($forwarded_for)) {
if (!phutil_nonempty_string($forwarded_for)) {
return;
}