1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01: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); exit($err);
} else if ($repository->isGit() || $repository->isHg()) { } else if ($repository->isGit() || $repository->isHg()) {
$username = getenv(DiffusionCommitHookEngine::ENV_USER); $username = getenv(DiffusionCommitHookEngine::ENV_USER);
if (!strlen($username)) { if (!phutil_nonempty_string($username)) {
throw new Exception( throw new Exception(
pht( pht(
'No Direct Pushes: You are pushing directly to a hosted repository. '. 'No Direct Pushes: You are pushing directly to a hosted repository. '.
@ -181,17 +181,17 @@ $engine->setStdin($stdin);
$engine->setOriginalArgv(array_slice($argv, 2)); $engine->setOriginalArgv(array_slice($argv, 2));
$remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS); $remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS);
if (strlen($remote_address)) { if (phutil_nonempty_string($remote_address)) {
$engine->setRemoteAddress($remote_address); $engine->setRemoteAddress($remote_address);
} }
$remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL); $remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL);
if (strlen($remote_protocol)) { if (phutil_nonempty_string($remote_protocol)) {
$engine->setRemoteProtocol($remote_protocol); $engine->setRemoteProtocol($remote_protocol);
} }
$request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST); $request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST);
if (strlen($request_identifier)) { if (phutil_nonempty_string($request_identifier)) {
$engine->setRequestIdentifier($request_identifier); $engine->setRequestIdentifier($request_identifier);
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,7 +15,7 @@ abstract class AphrontSite extends Phobject {
protected function isHostMatch($host, array $uris) { protected function isHostMatch($host, array $uris) {
foreach ($uris as $uri) { foreach ($uris as $uri) {
if (!strlen($uri)) { if (!phutil_nonempty_string($uri)) {
continue; 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 // If no base URI has been configured yet, match this site so the user
// can follow setup instructions. // can follow setup instructions.
$base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri'); $base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri');
if (!strlen($base_uri)) { if (!phutil_nonempty_string($base_uri)) {
return new PhabricatorPlatformSite(); return new PhabricatorPlatformSite();
} }

View file

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

View file

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

View file

@ -43,7 +43,7 @@ final class PhabricatorProjectProjectPHIDType extends PhabricatorPHIDType {
$handle->setName($name); $handle->setName($name);
if (strlen($slug)) { if (phutil_nonempty_string($slug)) {
$handle->setObjectName('#'.$slug); $handle->setObjectName('#'.$slug);
$handle->setMailStampName('#'.$slug); $handle->setMailStampName('#'.$slug);
$handle->setURI("/tag/{$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']; $forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (!strlen($forwarded_for)) { if (!phutil_nonempty_string($forwarded_for)) {
return; return;
} }