@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+27 -27
+4 -4
scripts/repository/commit_hook.php
··· 119 119 exit($err); 120 120 } else if ($repository->isGit() || $repository->isHg()) { 121 121 $username = getenv(DiffusionCommitHookEngine::ENV_USER); 122 - if (!strlen($username)) { 122 + if (!phutil_nonempty_string($username)) { 123 123 throw new Exception( 124 124 pht( 125 125 'No Direct Pushes: You are pushing directly to a hosted repository. '. ··· 181 181 $engine->setOriginalArgv(array_slice($argv, 2)); 182 182 183 183 $remote_address = getenv(DiffusionCommitHookEngine::ENV_REMOTE_ADDRESS); 184 - if (strlen($remote_address)) { 184 + if (phutil_nonempty_string($remote_address)) { 185 185 $engine->setRemoteAddress($remote_address); 186 186 } 187 187 188 188 $remote_protocol = getenv(DiffusionCommitHookEngine::ENV_REMOTE_PROTOCOL); 189 - if (strlen($remote_protocol)) { 189 + if (phutil_nonempty_string($remote_protocol)) { 190 190 $engine->setRemoteProtocol($remote_protocol); 191 191 } 192 192 193 193 $request_identifier = getenv(DiffusionCommitHookEngine::ENV_REQUEST); 194 - if (strlen($request_identifier)) { 194 + if (phutil_nonempty_string($request_identifier)) { 195 195 $engine->setRequestIdentifier($request_identifier); 196 196 } 197 197
+4 -4
scripts/ssh/ssh-auth.php
··· 36 36 37 37 $authstruct = null; 38 38 39 - if (strlen($authstruct_raw)) { 39 + if (phutil_nonempty_string($authstruct_raw)) { 40 40 try { 41 41 $authstruct = phutil_json_decode($authstruct_raw); 42 42 } catch (Exception $ex) { ··· 82 82 // Strip out newlines and other nonsense from the key type and key body. 83 83 $type = $ssh_key->getKeyType(); 84 84 $type = preg_replace('@[\x00-\x20]+@', '', $type); 85 - if (!strlen($type)) { 85 + if (!phutil_nonempty_string($type)) { 86 86 continue; 87 87 } 88 88 89 89 $key = $ssh_key->getKeyBody(); 90 90 $key = preg_replace('@[\x00-\x20]+@', '', $key); 91 - if (!strlen($key)) { 91 + if (!phutil_nonempty_string($key)) { 92 92 continue; 93 93 } 94 94 ··· 135 135 136 136 $cmd = csprintf('%s %Ls', $bin, $key_argv); 137 137 138 - if (strlen($instance)) { 138 + if (phutil_nonempty_string($instance)) { 139 139 $cmd = csprintf('PHABRICATOR_INSTANCE=%s %C', $instance, $cmd); 140 140 } 141 141
+2 -2
scripts/ssh/ssh-exec.php
··· 103 103 '--phabricator-ssh-device', 104 104 $user_name, 105 105 $device_name)); 106 - } else if (strlen($user_name)) { 106 + } else if (phutil_nonempty_string($user_name)) { 107 107 $user = id(new PhabricatorPeopleQuery()) 108 108 ->setViewer(PhabricatorUser::getOmnipotentUser()) 109 109 ->withUsernames(array($user_name)) ··· 117 117 118 118 id(new PhabricatorAuthSessionEngine()) 119 119 ->willServeRequestForUser($user); 120 - } else if (strlen($device_name)) { 120 + } else if (phutil_nonempty_string($device_name)) { 121 121 if (!$remote_address) { 122 122 throw new Exception( 123 123 pht(
+1 -1
scripts/symbols/generate_ctags_symbols.php
··· 39 39 $futures = array(); 40 40 41 41 foreach (explode("\n", trim($input)) as $file) { 42 - if (!strlen($file)) { 42 + if (!phutil_nonempty_string($file)) { 43 43 continue; 44 44 } 45 45
+1 -1
scripts/symbols/generate_php_symbols.php
··· 27 27 $futures = array(); 28 28 29 29 foreach (explode("\n", trim($input)) as $file) { 30 - if (!strlen($file)) { 30 + if (!phutil_nonempty_string($file)) { 31 31 continue; 32 32 } 33 33
+4 -4
src/aphront/AphrontRequest.php
··· 66 66 } 67 67 68 68 public static function parseURILineRange($range, $limit) { 69 - if (!strlen($range)) { 69 + if (!phutil_nonempty_string($range)) { 70 70 return null; 71 71 } 72 72 ··· 234 234 235 235 $raw_data = phutil_string_cast($this->requestData[$name]); 236 236 $raw_data = trim($raw_data); 237 - if (!strlen($raw_data)) { 237 + if (!phutil_nonempty_string($raw_data)) { 238 238 return $default; 239 239 } 240 240 ··· 499 499 // domain is. This makes setup easier, and we'll tell administrators to 500 500 // configure a base domain during the setup process. 501 501 $base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri'); 502 - if (!strlen($base_uri)) { 502 + if (!phutil_nonempty_string($base_uri)) { 503 503 return new PhutilURI('http://'.$host.'/'); 504 504 } 505 505 ··· 956 956 $submit_cookie = PhabricatorCookies::COOKIE_SUBMIT; 957 957 958 958 $submit_key = $this->getCookie($submit_cookie); 959 - if (strlen($submit_key)) { 959 + if (phutil_nonempty_string($submit_key)) { 960 960 $this->clearCookie($submit_cookie); 961 961 $this->submitKey = $submit_key; 962 962 }
+1 -1
src/aphront/configuration/AphrontApplicationConfiguration.php
··· 823 823 $raw_input = PhabricatorStartup::getRawInput(); 824 824 $parser = new PhutilQueryStringParser(); 825 825 826 - if (strlen($raw_input)) { 826 + if (phutil_nonempty_string($raw_input)) { 827 827 $content_type = idx($_SERVER, 'CONTENT_TYPE'); 828 828 $is_multipart = preg_match('@^multipart/form-data@i', $content_type); 829 829 if ($is_multipart) {
+1 -1
src/aphront/response/AphrontAjaxResponse.php
··· 64 64 if ($viewer) { 65 65 $postprocessor_key = $viewer->getUserSetting( 66 66 PhabricatorAccessibilitySetting::SETTINGKEY); 67 - if (strlen($postprocessor_key)) { 67 + if (phutil_nonempty_string($postprocessor_key)) { 68 68 $response->setPostprocessorKey($postprocessor_key); 69 69 } 70 70 }
+1 -1
src/aphront/response/AphrontFileResponse.php
··· 19 19 } 20 20 21 21 public function setDownload($download) { 22 - if (!strlen($download)) { 22 + if (!phutil_nonempty_string($download)) { 23 23 $download = 'untitled'; 24 24 } 25 25 $this->download = $download;
+1 -1
src/aphront/response/AphrontWebpageResponse.php
··· 21 21 22 22 public function buildResponseString() { 23 23 $unexpected_output = $this->getUnexpectedOutput(); 24 - if (strlen($unexpected_output)) { 24 + if (phutil_nonempty_string($unexpected_output)) { 25 25 $style = array( 26 26 'background: linear-gradient(180deg, #eeddff, #ddbbff);', 27 27 'white-space: pre-wrap;',
+1 -1
src/aphront/sink/AphrontPHPHTTPSink.php
··· 8 8 protected function emitHTTPStatus($code, $message = '') { 9 9 if ($code != 200) { 10 10 $header = "HTTP/1.0 {$code}"; 11 - if (strlen($message)) { 11 + if (phutil_nonempty_string($message)) { 12 12 $header .= " {$message}"; 13 13 } 14 14 header($header);
+1 -1
src/aphront/site/AphrontSite.php
··· 15 15 16 16 protected function isHostMatch($host, array $uris) { 17 17 foreach ($uris as $uri) { 18 - if (!strlen($uri)) { 18 + if (!phutil_nonempty_string($uri)) { 19 19 continue; 20 20 } 21 21
+1 -1
src/aphront/site/PhabricatorPlatformSite.php
··· 14 14 // If no base URI has been configured yet, match this site so the user 15 15 // can follow setup instructions. 16 16 $base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri'); 17 - if (!strlen($base_uri)) { 17 + if (!phutil_nonempty_string($base_uri)) { 18 18 return new PhabricatorPlatformSite(); 19 19 } 20 20
+1 -1
src/aphront/site/PhabricatorResourceSite.php
··· 14 14 $host = $request->getHost(); 15 15 16 16 $uri = PhabricatorEnv::getEnvConfig('security.alternate-file-domain'); 17 - if (!strlen($uri)) { 17 + if (!phutil_nonempty_string($uri)) { 18 18 return null; 19 19 } 20 20
+1 -1
src/aphront/site/PhabricatorShortSite.php
··· 14 14 $host = $request->getHost(); 15 15 16 16 $uri = PhabricatorEnv::getEnvConfig('phurl.short-uri'); 17 - if (!strlen($uri)) { 17 + if (!phutil_nonempty_string($uri)) { 18 18 return null; 19 19 } 20 20
+1 -1
src/applications/project/phid/PhabricatorProjectProjectPHIDType.php
··· 43 43 44 44 $handle->setName($name); 45 45 46 - if (strlen($slug)) { 46 + if (phutil_nonempty_string($slug)) { 47 47 $handle->setObjectName('#'.$slug); 48 48 $handle->setMailStampName('#'.$slug); 49 49 $handle->setURI("/tag/{$slug}/");
+1 -1
support/startup/preamble-utils.php
··· 21 21 } 22 22 23 23 $forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR']; 24 - if (!strlen($forwarded_for)) { 24 + if (!phutil_nonempty_string($forwarded_for)) { 25 25 return; 26 26 } 27 27