Merge remote-tracking branch 'upstream/master'

* upstream/master:
  Correct Aphlict websocket URI construction after PHP8 compatibility changes
  Addressing PHP8 incompatibilities - Miscellaneous
  Addressing PHP8 incompatibilities - Conduit
  Addressing some PHP8 incompatibilities - Dashboard
  Addressing some PHP8 incompatibilities - Misc. Applications
  Updates for Mercurial's HTTP protocol
  Addressing some PHP 8 incompatibilities - Remarkup
  Addressing some PHP8 incompatibilities - Diffusion & Differential
  Addressing some PHP8 incompatibilities - ProfileMenuItem
  Addressing some PHP 8 incompatibilities
  Fix support for pk-zip compressed figlet font files
  Update Figlet implementation to be PHP8 compatible
  Fix file PHID extraction in Pholio
This commit is contained in:
Moin 2024-10-15 11:02:51 +02:00
commit cc8a27af16
No known key found for this signature in database
GPG key ID: BDB9B5A617C0BC91
219 changed files with 734 additions and 629 deletions

View file

@ -10,25 +10,25 @@ insert_final_newline = true
max_line_length = 80 max_line_length = 80
[.arclint] [.arclint]
max_line_length = max_line_length = unset
[resources/sql/**.sql] [resources/sql/**.sql]
max_line_length = max_line_length = unset
[scripts/install/install_*.sh] [scripts/install/install_*.sh]
max_line_length = max_line_length = unset
[src/applications/differential/parser/__tests__/data/*.diff] [src/applications/differential/parser/__tests__/data/*.diff]
trim_trailing_whitespace = false trim_trailing_whitespace = false
[src/applications/differential/parser/__tests__/messages/long-title.txt] [src/applications/differential/parser/__tests__/messages/long-title.txt]
max_line_length = max_line_length = unset
[src/applications/diffusion/ssh/__tests__/hgwiredata/*.txt] [src/applications/diffusion/ssh/__tests__/hgwiredata/*.txt]
max_line_length = max_line_length = unset
[externals/**] [externals/**]
indent_style = indent_style = unset
indent_size = indent_size = unset
trim_trailing_whitespace = false trim_trailing_whitespace = false
insert_final_newline = false insert_final_newline = false

2
.gitignore vendored
View file

@ -36,6 +36,8 @@
# NPM local packages # NPM local packages
/support/aphlict/server/node_modules/ /support/aphlict/server/node_modules/
/support/aphlict/server/package.json
/support/aphlict/server/package-lock.json
# Places for users to add custom resources. # Places for users to add custom resources.
/resources/cows/custom/* /resources/cows/custom/*

View file

@ -140,20 +140,22 @@ class Text_Figlet
if (!$compressed) { if (!$compressed) {
/* ZIPed font */ /* ZIPed font */
if (fread($fp, 2) == 'PK') { if (fread($fp, 2) == 'PK') {
if (!function_exists('zip_open')) {
return self::raiseError('Cannot load ZIP compressed fonts since'
. ' ZIP PHP extension is not available.',
5);
}
fclose($fp); fclose($fp);
if (!($fp = zip_open($filename))) { $zip = new ZipArchive();
return self::raiseError('Cannot open figlet font file ' . $filename, 2); $open_flag = 0;
// The RDONLY flag was only introduced in 7.4.3.
if (defined('ZipArchive::RDONLY')) {
$open_flag = ZipArchive::RDONLY;
}
$open_result = $zip->open($filename, $open_flag);
if ($open_result !== true) {
return self::raiseError('Cannot open figlet font file ' .
$filename . ', got error: ' . $open_result, 2);
} }
$name = zip_entry_name(zip_read($fp)); $name = $zip->getNameIndex(0);
zip_close($fp); $zip->close();
if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) {
return self::raiseError('Cannot open figlet font file ' . $filename, 2); return self::raiseError('Cannot open figlet font file ' . $filename, 2);
@ -231,7 +233,7 @@ class Text_Figlet
$i = hexdec(substr($i, 2)); $i = hexdec(substr($i, 2));
} else { } else {
// If octal // If octal
if ($i{0} === '0' && $i !== '0' || substr($i, 0, 2) == '-0') { if ($i[0] === '0' && $i !== '0' || substr($i, 0, 2) == '-0') {
$i = octdec($i); $i = octdec($i);
} }
} }
@ -274,7 +276,7 @@ class Text_Figlet
$lt = hexdec(substr($str, $i+2, 4)); $lt = hexdec(substr($str, $i+2, 4));
$i += 5; $i += 5;
} else { } else {
$lt = ord($str{$i}); $lt = ord($str[$i]);
} }
$hb = preg_quote($this->hardblank, '/'); $hb = preg_quote($this->hardblank, '/');

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 ($username === null || !strlen($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 ($remote_address !== false && strlen($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 ($remote_protocol !== false && strlen($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 ($request_identifier !== false && strlen($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 ($authstruct_raw !== null && strlen($authstruct_raw)) {
try { try {
$authstruct = phutil_json_decode($authstruct_raw); $authstruct = phutil_json_decode($authstruct_raw);
} catch (Exception $ex) { } catch (Exception $ex) {
@ -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 ($instance !== null && strlen($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 ($user_name !== null && strlen($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 ($device_name !== null && strlen($device_name)) {
if (!$remote_address) { if (!$remote_address) {
throw new Exception( throw new Exception(
pht( pht(

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 ($range === null || !strlen($range)) {
return null; return null;
} }
@ -448,11 +448,10 @@ final class AphrontRequest extends Phobject {
} }
private function getPrefixedCookieName($name) { private function getPrefixedCookieName($name) {
if (strlen($this->cookiePrefix)) { if ($this->cookiePrefix !== null && strlen($this->cookiePrefix)) {
return $this->cookiePrefix.'_'.$name; return $this->cookiePrefix.'_'.$name;
} else {
return $name;
} }
return $name;
} }
public function getCookie($name, $default = null) { public function getCookie($name, $default = null) {
@ -499,7 +498,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 ($base_uri === null || !strlen($base_uri)) {
return new PhutilURI('http://'.$host.'/'); return new PhutilURI('http://'.$host.'/');
} }
@ -956,7 +955,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 ($submit_key !== null && strlen($submit_key)) {
$this->clearCookie($submit_cookie); $this->clearCookie($submit_cookie);
$this->submitKey = $submit_key; $this->submitKey = $submit_key;
} }

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 ($postprocessor_key !== null && strlen($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 ($download === null || !strlen($download)) {
$download = 'untitled'; $download = 'untitled';
} }
$this->download = $download; $this->download = $download;
@ -113,7 +113,8 @@ final class AphrontFileResponse extends AphrontResponse {
$headers[] = array('Content-Length', $content_len); $headers[] = array('Content-Length', $content_len);
} }
if (strlen($this->getDownload())) { $download = $this->getDownload();
if ($download !== null && strlen($download)) {
$headers[] = array('X-Download-Options', 'noopen'); $headers[] = array('X-Download-Options', 'noopen');
$filename = $this->getDownload(); $filename = $this->getDownload();
@ -150,7 +151,7 @@ final class AphrontFileResponse extends AphrontResponse {
$begin = (int)$matches[1]; $begin = (int)$matches[1];
// The "Range" may be "200-299" or "200-", meaning "until end of file". // The "Range" may be "200-299" or "200-", meaning "until end of file".
if (strlen($matches[2])) { if ($matches[2] !== null && strlen($matches[2])) {
$range_end = (int)$matches[2]; $range_end = (int)$matches[2];
$end = $range_end + 1; $end = $range_end + 1;
} else { } else {

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 ($unexpected_output !== null && strlen($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

@ -16,7 +16,7 @@ final class AlmanacPropertyEditController
$cancel_uri = $object->getURI(); $cancel_uri = $object->getURI();
$property_key = $request->getStr('key'); $property_key = $request->getStr('key');
if (!strlen($property_key)) { if (!phutil_nonempty_string($property_key)) {
return $this->buildPropertyKeyResponse($cancel_uri, null); return $this->buildPropertyKeyResponse($cancel_uri, null);
} else { } else {
$error = null; $error = null;

View file

@ -58,7 +58,7 @@ final class AlmanacKeys extends Phobject {
public static function getClusterSSHUser() { public static function getClusterSSHUser() {
$username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); $username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user');
if (strlen($username)) { if ($username !== null && strlen($username)) {
return $username; return $username;
} }

View file

@ -89,7 +89,7 @@ final class PhabricatorCookies extends Phobject {
// temporary and clearing it when users log out. // temporary and clearing it when users log out.
$value = $request->getCookie(self::COOKIE_CLIENTID); $value = $request->getCookie(self::COOKIE_CLIENTID);
if (!strlen($value)) { if ($value === null || !strlen($value)) {
$request->setTemporaryCookie( $request->setTemporaryCookie(
self::COOKIE_CLIENTID, self::COOKIE_CLIENTID,
Filesystem::readRandomCharacters(16)); Filesystem::readRandomCharacters(16));
@ -164,7 +164,7 @@ final class PhabricatorCookies extends Phobject {
// Old cookies look like: /uri // Old cookies look like: /uri
// New cookies look like: timestamp,/uri // New cookies look like: timestamp,/uri
if (!strlen($cookie)) { if (!phutil_nonempty_string($cookie)) {
return null; return null;
} }

View file

@ -282,7 +282,7 @@ abstract class PhabricatorAuthController extends PhabricatorController {
$viewer, $viewer,
PhabricatorAuthLoginMessageType::MESSAGEKEY); PhabricatorAuthLoginMessageType::MESSAGEKEY);
if (!strlen($text)) { if ($text === null || !strlen($text)) {
return null; return null;
} }

View file

@ -25,7 +25,7 @@ final class PhabricatorAuthRegisterController
$invite = $this->loadInvite(); $invite = $this->loadInvite();
$is_setup = false; $is_setup = false;
if (strlen($account_key)) { if ($account_key !== null && strlen($account_key)) {
$result = $this->loadAccountForRegistrationOrLinking($account_key); $result = $this->loadAccountForRegistrationOrLinking($account_key);
list($account, $provider, $response) = $result; list($account, $provider, $response) = $result;
$is_default = false; $is_default = false;
@ -251,9 +251,9 @@ final class PhabricatorAuthRegisterController
$require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name'); $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name');
$e_username = strlen($value_username) ? null : true; $e_username = phutil_nonempty_string($value_username) ? null : true;
$e_realname = $require_real_name ? true : null; $e_realname = $require_real_name ? true : null;
$e_email = strlen($value_email) ? null : true; $e_email = phutil_nonempty_string($value_email) ? null : true;
$e_password = true; $e_password = true;
$e_captcha = true; $e_captcha = true;
@ -295,7 +295,7 @@ final class PhabricatorAuthRegisterController
if ($can_edit_username) { if ($can_edit_username) {
$value_username = $request->getStr('username'); $value_username = $request->getStr('username');
if (!strlen($value_username)) { if (!phutil_nonempty_string($value_username)) {
$e_username = pht('Required'); $e_username = pht('Required');
$errors[] = pht('Username is required.'); $errors[] = pht('Username is required.');
} else if (!PhabricatorUser::validateUsername($value_username)) { } else if (!PhabricatorUser::validateUsername($value_username)) {
@ -330,7 +330,7 @@ final class PhabricatorAuthRegisterController
if ($can_edit_email) { if ($can_edit_email) {
$value_email = $request->getStr('email'); $value_email = $request->getStr('email');
if (!strlen($value_email)) { if (!phutil_nonempty_string($value_email)) {
$e_email = pht('Required'); $e_email = pht('Required');
$errors[] = pht('Email is required.'); $errors[] = pht('Email is required.');
} else if (!PhabricatorUserEmail::isValidAddress($value_email)) { } else if (!PhabricatorUserEmail::isValidAddress($value_email)) {
@ -350,7 +350,7 @@ final class PhabricatorAuthRegisterController
if ($can_edit_realname) { if ($can_edit_realname) {
$value_realname = $request->getStr('realName'); $value_realname = $request->getStr('realName');
if (!strlen($value_realname) && $require_real_name) { if (!phutil_nonempty_string($value_realname) && $require_real_name) {
$e_realname = pht('Required'); $e_realname = pht('Required');
$errors[] = pht('Real name is required.'); $errors[] = pht('Real name is required.');
} else { } else {

View file

@ -54,10 +54,10 @@ final class PhabricatorAuthSSHKeyEditController
$cancel_uri); $cancel_uri);
$v_name = $key->getName(); $v_name = $key->getName();
$e_name = strlen($v_name) ? null : true; $e_name = $v_name !== null && strlen($v_name) ? null : true;
$v_key = $key->getEntireKey(); $v_key = $key->getEntireKey();
$e_key = strlen($v_key) ? null : true; $e_key = $v_key !== null && strlen($v_key) ? null : true;
$validation_exception = null; $validation_exception = null;
if ($request->isFormPost()) { if ($request->isFormPost()) {

View file

@ -40,7 +40,7 @@ final class PhabricatorAuthSetExternalController
$text = PhabricatorAuthMessage::loadMessageText( $text = PhabricatorAuthMessage::loadMessageText(
$viewer, $viewer,
PhabricatorAuthLinkMessageType::MESSAGEKEY); PhabricatorAuthLinkMessageType::MESSAGEKEY);
if (!strlen($text)) { if (!phutil_nonempty_string($text)) {
$text = pht( $text = pht(
'You can link your %s account to an external account to '. 'You can link your %s account to an external account to '.
'allow you to log in more easily in the future. To continue, choose '. 'allow you to log in more easily in the future. To continue, choose '.

View file

@ -31,7 +31,7 @@ final class PhabricatorAuthStartController
$session_token = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); $session_token = $request->getCookie(PhabricatorCookies::COOKIE_SESSION);
$did_clear = $request->getStr('cleared'); $did_clear = $request->getStr('cleared');
if (strlen($session_token)) { if ($session_token !== null && strlen($session_token)) {
$kind = PhabricatorAuthSessionEngine::getSessionKindFromToken( $kind = PhabricatorAuthSessionEngine::getSessionKindFromToken(
$session_token); $session_token);
switch ($kind) { switch ($kind) {
@ -98,7 +98,7 @@ final class PhabricatorAuthStartController
} }
$next_uri = $request->getStr('next'); $next_uri = $request->getStr('next');
if (!strlen($next_uri)) { if (phutil_nonempty_string($next_uri)) {
if ($this->getDelegatingController()) { if ($this->getDelegatingController()) {
// Only set a next URI from the request path if this controller was // Only set a next URI from the request path if this controller was
// delegated to, which happens when a user tries to view a page which // delegated to, which happens when a user tries to view a page which
@ -112,7 +112,7 @@ final class PhabricatorAuthStartController
} }
if (!$request->isFormPost()) { if (!$request->isFormPost()) {
if (strlen($next_uri)) { if (phutil_nonempty_string($next_uri)) {
PhabricatorCookies::setNextURICookie($request, $next_uri); PhabricatorCookies::setNextURICookie($request, $next_uri);
} }
PhabricatorCookies::setClientIDCookie($request); PhabricatorCookies::setClientIDCookie($request);
@ -226,7 +226,7 @@ final class PhabricatorAuthStartController
$via_header = AphrontRequest::getViaHeaderName(); $via_header = AphrontRequest::getViaHeaderName();
$via_uri = AphrontRequest::getHTTPHeader($via_header); $via_uri = AphrontRequest::getHTTPHeader($via_header);
if (strlen($via_uri)) { if ($via_uri !== null && strlen($via_uri)) {
PhabricatorCookies::setNextURICookie($request, $via_uri, $force = true); PhabricatorCookies::setNextURICookie($request, $via_uri, $force = true);
} }

View file

@ -83,7 +83,7 @@ final class PhabricatorAuthFactorProviderViewController
$custom_enroll = $provider->getEnrollMessage(); $custom_enroll = $provider->getEnrollMessage();
if (strlen($custom_enroll)) { if ($custom_enroll !== null && strlen($custom_enroll)) {
$view->addSectionHeader( $view->addSectionHeader(
pht('Custom Enroll Message'), pht('Custom Enroll Message'),
PHUIPropertyListView::ICON_SUMMARY); PHUIPropertyListView::ICON_SUMMARY);

View file

@ -414,7 +414,7 @@ abstract class PhabricatorAuthFactor extends Phobject {
$sync_token = null; $sync_token = null;
$sync_key = $request->getStr($this->getMFASyncTokenFormKey()); $sync_key = $request->getStr($this->getMFASyncTokenFormKey());
if (strlen($sync_key)) { if (phutil_nonempty_string($sync_key)) {
$sync_key_digest = PhabricatorHash::digestWithNamedKey( $sync_key_digest = PhabricatorHash::digestWithNamedKey(
$sync_key, $sync_key,
PhabricatorAuthMFASyncTemporaryTokenType::DIGEST_KEY); PhabricatorAuthMFASyncTemporaryTokenType::DIGEST_KEY);

View file

@ -4,7 +4,7 @@ final class PhabricatorAuthPasswordException
extends Exception { extends Exception {
private $passwordError; private $passwordError;
private $confirmErorr; private $confirmError;
public function __construct( public function __construct(
$message, $message,

View file

@ -57,6 +57,9 @@ final class PhabricatorAuthChallenge
assert_instances_of($challenges, __CLASS__); assert_instances_of($challenges, __CLASS__);
$token_list = $request->getStr(self::HTTPKEY); $token_list = $request->getStr(self::HTTPKEY);
if ($token_list === null) {
return;
}
$token_list = explode(' ', $token_list); $token_list = explode(' ', $token_list);
$token_map = array(); $token_map = array();

View file

@ -74,7 +74,7 @@ abstract class PhabricatorController extends AphrontController {
$session_engine = new PhabricatorAuthSessionEngine(); $session_engine = new PhabricatorAuthSessionEngine();
$phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); $phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION);
if (strlen($phsid)) { if ($phsid !== null && strlen($phsid)) {
$session_user = $session_engine->loadUserForSession( $session_user = $session_engine->loadUserForSession(
PhabricatorAuthSession::TYPE_WEB, PhabricatorAuthSession::TYPE_WEB,
$phsid); $phsid);

View file

@ -113,7 +113,7 @@ abstract class CelerityResourceController extends PhabricatorController {
$range = AphrontRequest::getHTTPHeader('Range'); $range = AphrontRequest::getHTTPHeader('Range');
if (strlen($range)) { if ($range !== null && strlen($range)) {
$response->setContentLength(strlen($data)); $response->setContentLength(strlen($data));
list($range_begin, $range_end) = $response->parseHTTPRange($range); list($range_begin, $range_end) = $response->parseHTTPRange($range);

View file

@ -290,7 +290,7 @@ final class PhabricatorConduitAPIController
} }
$token_string = idx($metadata, 'token'); $token_string = idx($metadata, 'token');
if (strlen($token_string)) { if ($token_string !== null && strlen($token_string)) {
if (strlen($token_string) != 32) { if (strlen($token_string) != 32) {
return array( return array(
@ -683,7 +683,7 @@ final class PhabricatorConduitAPIController
// Otherwise, look for a single parameter called 'params' which has the // Otherwise, look for a single parameter called 'params' which has the
// entire param dictionary JSON encoded. // entire param dictionary JSON encoded.
$params_json = $request->getStr('params'); $params_json = $request->getStr('params');
if (strlen($params_json)) { if (phutil_nonempty_string($params_json)) {
$params = null; $params = null;
try { try {
$params = phutil_json_decode($params_json); $params = phutil_json_decode($params_json);

View file

@ -39,7 +39,7 @@ final class PhabricatorConduitSearchEngine
$query->withIsInternal(false); $query->withIsInternal(false);
$contains = $saved->getParameter('nameContains'); $contains = $saved->getParameter('nameContains');
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
$query->withNameContains($contains); $query->withNameContains($contains);
} }

View file

@ -11,7 +11,7 @@ final class PhabricatorBaseURISetupCheck extends PhabricatorSetupCheck {
$host_header = AphrontRequest::getHTTPHeader('Host'); $host_header = AphrontRequest::getHTTPHeader('Host');
if (strpos($host_header, '.') === false) { if (strpos($host_header, '.') === false) {
if (!strlen(trim($host_header))) { if ($host_header === null || !strlen(trim($host_header))) {
$name = pht('No "Host" Header'); $name = pht('No "Host" Header');
$summary = pht('No "Host" header present in request.'); $summary = pht('No "Host" header present in request.');
$message = pht( $message = pht(

View file

@ -53,7 +53,7 @@ final class PhabricatorDaemonsSetupCheck extends PhabricatorSetupCheck {
} }
$expect_user = PhabricatorEnv::getEnvConfig('phd.user'); $expect_user = PhabricatorEnv::getEnvConfig('phd.user');
if (strlen($expect_user)) { if ($expect_user !== null && strlen($expect_user)) {
try { try {
$all_daemons = id(new PhabricatorDaemonLogQuery()) $all_daemons = id(new PhabricatorDaemonLogQuery())

View file

@ -124,7 +124,7 @@ final class PhabricatorPHPPreflightSetupCheck extends PhabricatorSetupCheck {
} }
$open_basedir = ini_get('open_basedir'); $open_basedir = ini_get('open_basedir');
if (strlen($open_basedir)) { if ($open_basedir !== null && strlen($open_basedir)) {
// If `open_basedir` is set, just fatal. It's technically possible for // If `open_basedir` is set, just fatal. It's technically possible for
// us to run with certain values of `open_basedir`, but: we can only // us to run with certain values of `open_basedir`, but: we can only
// raise fatal errors from preflight steps, so we'd have to do this check // raise fatal errors from preflight steps, so we'd have to do this check

View file

@ -122,7 +122,7 @@ abstract class PhabricatorSetupCheck extends Phobject {
$db_cache = new PhabricatorKeyValueDatabaseCache(); $db_cache = new PhabricatorKeyValueDatabaseCache();
try { try {
$value = $db_cache->getKey('phabricator.setup.issue-keys'); $value = $db_cache->getKey('phabricator.setup.issue-keys');
if (!strlen($value)) { if ($value === null || !strlen($value)) {
return null; return null;
} }
return phutil_json_decode($value); return phutil_json_decode($value);

View file

@ -151,19 +151,19 @@ final class PhabricatorStorageSetupCheck extends PhabricatorSetupCheck {
$how_many = 0; $how_many = 0;
if (strlen($access_key)) { if ($access_key !== null && strlen($access_key)) {
$how_many++; $how_many++;
} }
if (strlen($secret_key)) { if ($secret_key !== null && strlen($secret_key)) {
$how_many++; $how_many++;
} }
if (strlen($region)) { if ($region !== null && strlen($region)) {
$how_many++; $how_many++;
} }
if (strlen($endpoint)) { if ($endpoint !== null && strlen($endpoint)) {
$how_many++; $how_many++;
} }

View file

@ -23,7 +23,7 @@ final class PhabricatorWebServerSetupCheck extends PhabricatorSetupCheck {
} }
$base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri'); $base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri');
if (!strlen($base_uri)) { if ($base_uri === null || !strlen($base_uri)) {
// If `phabricator.base-uri` is not set then we can't really do // If `phabricator.base-uri` is not set then we can't really do
// anything. // anything.
return; return;

View file

@ -85,14 +85,14 @@ final class PhabricatorConfigConsoleController
$rows = array(); $rows = array();
foreach ($versions as $name => $info) { foreach ($versions as $name => $info) {
$branchpoint = $info['branchpoint']; $branchpoint = $info['branchpoint'];
if (strlen($branchpoint)) { if ($branchpoint !== null && strlen($branchpoint)) {
$branchpoint = substr($branchpoint, 0, 12); $branchpoint = substr($branchpoint, 0, 12);
} else { } else {
$branchpoint = null; $branchpoint = null;
} }
$version = $info['hash']; $version = $info['hash'];
if (strlen($version)) { if ($version !== null && strlen($version)) {
$version = substr($version, 0, 12); $version = substr($version, 0, 12);
} else { } else {
$version = pht('Unknown'); $version = pht('Unknown');

View file

@ -9,7 +9,7 @@ final class PhabricatorConfigModuleController
$all_modules = PhabricatorConfigModule::getAllModules(); $all_modules = PhabricatorConfigModule::getAllModules();
if (!strlen($key)) { if ($key === null || !strlen($key)) {
$key = head_key($all_modules); $key = head_key($all_modules);
} }

View file

@ -837,7 +837,7 @@ final class PhabricatorConfigDatabaseStatusController
$parts = array(); $parts = array();
foreach ($properties as $key => $property) { foreach ($properties as $key => $property) {
if (!strlen($property)) { if ($property === null || !strlen($property)) {
continue; continue;
} }

View file

@ -7,7 +7,7 @@ final class PhabricatorConfigSettingsListController
$viewer = $request->getViewer(); $viewer = $request->getViewer();
$filter = $request->getURIData('filter'); $filter = $request->getURIData('filter');
if (!strlen($filter)) { if ($filter === null || !strlen($filter)) {
$filter = 'settings'; $filter = 'settings';
} }

View file

@ -135,7 +135,8 @@ final class ConpherenceThreadQuery
} }
protected function buildGroupClause(AphrontDatabaseConnection $conn_r) { protected function buildGroupClause(AphrontDatabaseConnection $conn_r) {
if ($this->participantPHIDs !== null || strlen($this->fulltext)) { if ($this->participantPHIDs !== null
|| ($this->fulltext !== null && strlen($this->fulltext))) {
return qsprintf($conn_r, 'GROUP BY thread.id'); return qsprintf($conn_r, 'GROUP BY thread.id');
} else { } else {
return $this->buildApplicationSearchGroupClause($conn_r); return $this->buildApplicationSearchGroupClause($conn_r);
@ -152,7 +153,7 @@ final class ConpherenceThreadQuery
id(new ConpherenceParticipant())->getTableName()); id(new ConpherenceParticipant())->getTableName());
} }
if (strlen($this->fulltext)) { if ($this->fulltext !== null && strlen($this->fulltext)) {
$joins[] = qsprintf( $joins[] = qsprintf(
$conn, $conn,
'JOIN %T idx ON idx.threadPHID = thread.phid', 'JOIN %T idx ON idx.threadPHID = thread.phid',
@ -234,7 +235,7 @@ final class ConpherenceThreadQuery
$this->participantPHIDs); $this->participantPHIDs);
} }
if (strlen($this->fulltext)) { if ($this->fulltext !== null && strlen($this->fulltext)) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'MATCH(idx.corpus) AGAINST (%s IN BOOLEAN MODE)', 'MATCH(idx.corpus) AGAINST (%s IN BOOLEAN MODE)',

View file

@ -106,7 +106,7 @@ final class ConpherenceThreadSearchEngine
$engines = array(); $engines = array();
$fulltext = $query->getParameter('fulltext'); $fulltext = $query->getParameter('fulltext');
if (strlen($fulltext) && $conpherences) { if ($fulltext !== null && strlen($fulltext) && $conpherences) {
$context = $this->loadContextMessages($conpherences, $fulltext); $context = $this->loadContextMessages($conpherences, $fulltext);
$author_phids = array(); $author_phids = array();
@ -151,7 +151,7 @@ final class ConpherenceThreadSearchEngine
$icon = id(new PHUIIconView()) $icon = id(new PHUIIconView())
->setIcon($icon_name); ->setIcon($icon_name);
if (!strlen($fulltext)) { if ($fulltext === null || !strlen($fulltext)) {
$item = id(new PHUIObjectItemView()) $item = id(new PHUIObjectItemView())
->setObjectName($conpherence->getMonogram()) ->setObjectName($conpherence->getMonogram())
->setHeader($title) ->setHeader($title)

View file

@ -26,7 +26,7 @@ final class DarkConsoleController extends PhabricatorController {
} }
$visible = $request->getStr('visible'); $visible = $request->getStr('visible');
if (strlen($visible)) { if (phutil_nonempty_string($visible)) {
$this->writeDarkConsoleSetting( $this->writeDarkConsoleSetting(
PhabricatorDarkConsoleVisibleSetting::SETTINGKEY, PhabricatorDarkConsoleVisibleSetting::SETTINGKEY,
(int)$visible); (int)$visible);
@ -34,7 +34,7 @@ final class DarkConsoleController extends PhabricatorController {
} }
$tab = $request->getStr('tab'); $tab = $request->getStr('tab');
if (strlen($tab)) { if (phutil_nonempty_string($tab)) {
$this->writeDarkConsoleSetting( $this->writeDarkConsoleSetting(
PhabricatorDarkConsoleTabSetting::SETTINGKEY, PhabricatorDarkConsoleTabSetting::SETTINGKEY,
$tab); $tab);

View file

@ -114,6 +114,9 @@ final class DarkConsoleCore extends Phobject {
* need to convert it to UTF-8. * need to convert it to UTF-8.
*/ */
private function sanitizeForJSON($data) { private function sanitizeForJSON($data) {
if ($data === null) {
return '<null>';
}
if (is_object($data)) { if (is_object($data)) {
return '<object:'.get_class($data).'>'; return '<object:'.get_class($data).'>';
} else if (is_array($data)) { } else if (is_array($data)) {

View file

@ -32,7 +32,7 @@ final class PhabricatorDashboardAdjustController
$panel_ref = null; $panel_ref = null;
$panel_key = $request->getStr('panelKey'); $panel_key = $request->getStr('panelKey');
if (strlen($panel_key)) { if (phutil_nonempty_string($panel_key)) {
$panel_ref = $ref_list->getPanelRef($panel_key); $panel_ref = $ref_list->getPanelRef($panel_key);
if (!$panel_ref) { if (!$panel_ref) {
return new Aphront404Response(); return new Aphront404Response();
@ -42,7 +42,7 @@ final class PhabricatorDashboardAdjustController
} }
$column_key = $request->getStr('columnKey'); $column_key = $request->getStr('columnKey');
if (strlen($column_key)) { if (phutil_nonempty_string($column_key)) {
$columns = $ref_list->getColumns(); $columns = $ref_list->getColumns();
if (!isset($columns[$column_key])) { if (!isset($columns[$column_key])) {
return new Aphront404Response(); return new Aphront404Response();
@ -52,7 +52,7 @@ final class PhabricatorDashboardAdjustController
$after_ref = null; $after_ref = null;
$after_key = $request->getStr('afterKey'); $after_key = $request->getStr('afterKey');
if (strlen($after_key)) { if (phutil_nonempty_string($after_key)) {
$after_ref = $ref_list->getPanelRef($after_key); $after_ref = $ref_list->getPanelRef($after_key);
if (!$after_ref) { if (!$after_ref) {
return new Aphront404Response(); return new Aphront404Response();

View file

@ -15,7 +15,7 @@ final class PhabricatorDashboardPanelEditController
// editing. // editing.
$context_phid = $request->getStr('contextPHID'); $context_phid = $request->getStr('contextPHID');
if (strlen($context_phid)) { if (phutil_nonempty_string($context_phid)) {
$context = id(new PhabricatorObjectQuery()) $context = id(new PhabricatorObjectQuery())
->setViewer($viewer) ->setViewer($viewer)
->withPHIDs(array($context_phid)) ->withPHIDs(array($context_phid))

View file

@ -41,12 +41,12 @@ final class PhabricatorDashboardPanelTabsController
$op = $request->getURIData('op'); $op = $request->getURIData('op');
$after = $request->getStr('after'); $after = $request->getStr('after');
if (!strlen($after)) { if (!phutil_nonempty_string($after)) {
$after = null; $after = null;
} }
$target = $request->getStr('target'); $target = $request->getStr('target');
if (!strlen($target)) { if (!phutil_nonempty_string($target)) {
$target = null; $target = null;
} }
@ -103,7 +103,7 @@ final class PhabricatorDashboardPanelTabsController
$context_phid = $request->getStr('contextPHID'); $context_phid = $request->getStr('contextPHID');
$context = null; $context = null;
if (strlen($context_phid)) { if (phutil_nonempty_string($context_phid)) {
$context = id(new PhabricatorObjectQuery()) $context = id(new PhabricatorObjectQuery())
->setViewer($viewer) ->setViewer($viewer)
->withPHIDs(array($context_phid)) ->withPHIDs(array($context_phid))

View file

@ -101,7 +101,7 @@ final class PhabricatorDashboardTabsPanelType
$subpanel = idx($panels, $panel_id); $subpanel = idx($panels, $panel_id);
$name = idx($tab_spec, 'name'); $name = idx($tab_spec, 'name');
if (!strlen($name)) { if ($name === null || !strlen($name)) {
if ($subpanel) { if ($subpanel) {
$name = $subpanel->getName(); $name = $subpanel->getName();
} }

View file

@ -28,7 +28,7 @@ final class PhabricatorDashboardPanelDatasource
$query = new PhabricatorDashboardPanelQuery(); $query = new PhabricatorDashboardPanelQuery();
$raw_query = $this->getRawQuery(); $raw_query = $this->getRawQuery();
if (preg_match('/^[wW]\d+\z/', $raw_query)) { if ($raw_query !== null && preg_match('/^[wW]\d+\z/', $raw_query)) {
$id = trim($raw_query, 'wW'); $id = trim($raw_query, 'wW');
$id = (int)$id; $id = (int)$id;
$query->withIDs(array($id)); $query->withIDs(array($id));

View file

@ -55,6 +55,9 @@ final class DifferentialCreateDiffConduitAPIMethod
protected function execute(ConduitAPIRequest $request) { protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser(); $viewer = $request->getUser();
$change_data = $request->getValue('changes'); $change_data = $request->getValue('changes');
if ($change_data === null) {
throw new Exception(pht('Field "changes" must be non-empty.'));
}
$changes = array(); $changes = array();
foreach ($change_data as $dict) { foreach ($change_data as $dict) {

View file

@ -26,6 +26,9 @@ final class DifferentialCreateRawDiffConduitAPIMethod
protected function execute(ConduitAPIRequest $request) { protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser(); $viewer = $request->getUser();
$raw_diff = $request->getValue('diff'); $raw_diff = $request->getValue('diff');
if ($raw_diff === null || !strlen($raw_diff)) {
throw new Exception(pht('Field "raw_diff" must be non-empty.'));
}
$repository_phid = $request->getValue('repositoryPHID'); $repository_phid = $request->getValue('repositoryPHID');
if ($repository_phid) { if ($repository_phid) {

View file

@ -56,7 +56,7 @@ final class DifferentialGetCommitMessageConduitAPIMethod
// show "Field:" templates for some fields even if they are empty. // show "Field:" templates for some fields even if they are empty.
$edit_mode = $request->getValue('edit'); $edit_mode = $request->getValue('edit');
$is_any_edit = (bool)strlen($edit_mode); $is_any_edit = $edit_mode !== null && (bool)strlen($edit_mode);
$is_create = ($edit_mode == 'create'); $is_create = ($edit_mode == 'create');
$field_list = DifferentialCommitMessageField::newEnabledFields($viewer); $field_list = DifferentialCommitMessageField::newEnabledFields($viewer);
@ -115,7 +115,7 @@ final class DifferentialGetCommitMessageConduitAPIMethod
$is_title = ($field_key == $key_title); $is_title = ($field_key == $key_title);
if (!strlen($value)) { if ($value === null || !strlen($value)) {
if ($is_template) { if ($is_template) {
$commit_message[] = $label.': '; $commit_message[] = $label.': ';
} }

View file

@ -33,6 +33,9 @@ final class DifferentialParseCommitMessageConduitAPIMethod
} }
$corpus = $request->getValue('corpus'); $corpus = $request->getValue('corpus');
if ($corpus === null || !strlen($corpus)) {
throw new Exception(pht('Field "corpus" must be non-empty.'));
}
$field_map = $parser->parseFields($corpus); $field_map = $parser->parseFields($corpus);
$errors = $parser->getErrors(); $errors = $parser->getErrors();

View file

@ -30,9 +30,22 @@ final class DifferentialSetDiffPropertyConduitAPIMethod
} }
protected function execute(ConduitAPIRequest $request) { protected function execute(ConduitAPIRequest $request) {
$data = $request->getValue('data');
if ($data === null || !strlen($data)) {
throw new Exception(pht('Field "data" must be non-empty.'));
}
$diff_id = $request->getValue('diff_id'); $diff_id = $request->getValue('diff_id');
if ($diff_id === null) {
throw new Exception(pht('Field "diff_id" must be non-null.'));
}
$name = $request->getValue('name'); $name = $request->getValue('name');
$data = json_decode($request->getValue('data'), true); if ($name === null || !strlen($name)) {
throw new Exception(pht('Field "name" must be non-empty.'));
}
$data = json_decode($data, true);
self::updateDiffProperty($diff_id, $name, $data); self::updateDiffProperty($diff_id, $name, $data);
} }

View file

@ -39,13 +39,20 @@ final class DifferentialBranchField
$branch = $diff->getBranch(); $branch = $diff->getBranch();
$bookmark = $diff->getBookmark(); $bookmark = $diff->getBookmark();
if ($branch === null) {
$branch = '';
}
if ($bookmark === null) {
$bookmark = '';
}
if (strlen($branch) && strlen($bookmark)) { if (strlen($branch) && strlen($bookmark)) {
return pht('%s (bookmark) on %s (branch)', $bookmark, $branch); return pht('%s (bookmark) on %s (branch)', $bookmark, $branch);
} else if (strlen($bookmark)) { } else if (strlen($bookmark)) {
return pht('%s (bookmark)', $bookmark); return pht('%s (bookmark)', $bookmark);
} else if (strlen($branch)) { } else if (strlen($branch)) {
$onto = $diff->loadTargetBranch(); $onto = $diff->loadTargetBranch();
if (strlen($onto) && ($onto !== $branch)) { if ($onto !== null && strlen($onto) && ($onto !== $branch)) {
return pht( return pht(
'%s (branched from %s)', '%s (branched from %s)',
$branch, $branch,

View file

@ -218,7 +218,7 @@ final class DifferentialTransactionEditor
// No "$", to allow for branches like T123_demo. // No "$", to allow for branches like T123_demo.
$match = null; $match = null;
if (preg_match('/^T(\d+)/i', $branch, $match)) { if ($branch !== null && preg_match('/^T(\d+)/i', $branch, $match)) {
$task_id = $match[1]; $task_id = $match[1];
$tasks = id(new ManiphestTaskQuery()) $tasks = id(new ManiphestTaskQuery())
->setViewer($this->getActor()) ->setViewer($this->getActor())

View file

@ -60,7 +60,7 @@ abstract class DifferentialCommitMessageField
} }
public function renderFieldValue($value) { public function renderFieldValue($value) {
if (!strlen($value)) { if ($value === null || !strlen($value)) {
return null; return null;
} }

View file

@ -72,7 +72,7 @@ final class DifferentialRevisionIDCommitMessageField
} }
public function renderFieldValue($value) { public function renderFieldValue($value) {
if (!strlen($value)) { if ($value === null || !strlen($value)) {
return null; return null;
} }

View file

@ -325,7 +325,7 @@ final class DifferentialChangeset
public function getOldStatePathVector() { public function getOldStatePathVector() {
$path = $this->getOldFile(); $path = $this->getOldFile();
if (!strlen($path)) { if ($path === null || !strlen($path)) {
$path = $this->getFilename(); $path = $this->getFilename();
} }

View file

@ -251,6 +251,7 @@ final class DifferentialRevisionUpdateHistoryView extends AphrontView {
$content = phabricator_form( $content = phabricator_form(
$this->getUser(), $this->getUser(),
array( array(
'method' => 'GET',
'action' => '/D'.$revision_id.'#toc', 'action' => '/D'.$revision_id.'#toc',
), ),
array( array(

View file

@ -30,7 +30,7 @@ final class DiffusionBranchQueryConduitAPIMethod
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$contains = $request->getValue('contains'); $contains = $request->getValue('contains');
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
// See PHI958 (and, earlier, PHI720). If "patterns" are provided, pass // See PHI958 (and, earlier, PHI720). If "patterns" are provided, pass
// them to "git branch ..." to let callers test for reachability from // them to "git branch ..." to let callers test for reachability from
@ -80,7 +80,7 @@ final class DiffusionBranchQueryConduitAPIMethod
->setRepository($repository); ->setRepository($repository);
$contains = $request->getValue('contains'); $contains = $request->getValue('contains');
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
$query->withContainsCommit($contains); $query->withContainsCommit($contains);
} }

View file

@ -37,7 +37,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$path = $request->getValue('path'); $path = $request->getValue('path');
if (!strlen($path) || $path === '/') { if ($path === null || !strlen($path) || $path === '/') {
$path = null; $path = null;
} }
@ -282,8 +282,13 @@ final class DiffusionBrowseQueryConduitAPIMethod
$results = array(); $results = array();
$match_against = trim($path, '/'); if ($path !== null) {
$match_len = strlen($match_against); $match_against = trim($path, '/');
$match_len = strlen($match_against);
} else {
$match_against = '';
$match_len = 0;
}
// For the root, don't trim. For other paths, trim the "/" after we match. // For the root, don't trim. For other paths, trim the "/" after we match.
// We need this because Mercurial's canonical paths have no leading "/", // We need this because Mercurial's canonical paths have no leading "/",
@ -295,7 +300,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
if (strncmp($path, $match_against, $match_len)) { if (strncmp($path, $match_against, $match_len)) {
continue; continue;
} }
if (!strlen($path)) { if ($path === null || !strlen($path)) {
continue; continue;
} }
$remainder = substr($path, $trim_len); $remainder = substr($path, $trim_len);

View file

@ -45,17 +45,16 @@ final class DiffusionHistoryQueryConduitAPIMethod
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$commit_hash = $request->getValue('commit'); $commit_hash = $request->getValue('commit');
$against_hash = $request->getValue('against'); $against_hash = $request->getValue('against');
$path = $request->getValue('path');
if (!strlen($path)) {
$path = null;
}
$offset = $request->getValue('offset'); $offset = $request->getValue('offset');
$limit = $request->getValue('limit'); $limit = $request->getValue('limit');
if (strlen($against_hash)) { $path = $request->getValue('path');
$commit_range = "${against_hash}..${commit_hash}"; if ($path === null || !strlen($path)) {
$path = null;
}
if ($against_hash !== null && strlen($against_hash)) {
$commit_range = "{$against_hash}..{$commit_hash}";
} else { } else {
$commit_range = $commit_hash; $commit_range = $commit_hash;
} }

View file

@ -26,7 +26,7 @@ final class DiffusionBranchTableController extends DiffusionController {
); );
$contains = $drequest->getSymbolicCommit(); $contains = $drequest->getSymbolicCommit();
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
$params['contains'] = $contains; $params['contains'] = $contains;
} }

View file

@ -22,7 +22,7 @@ final class DiffusionBrowseController extends DiffusionController {
// list. // list.
$grep = $request->getStr('grep'); $grep = $request->getStr('grep');
if (strlen($grep)) { if (phutil_nonempty_string($grep)) {
return $this->browseSearch(); return $this->browseSearch();
} }
@ -290,6 +290,11 @@ final class DiffusionBrowseController extends DiffusionController {
$header = $this->buildHeaderView($drequest); $header = $this->buildHeaderView($drequest);
$header->setHeaderIcon('fa-folder-open'); $header->setHeaderIcon('fa-folder-open');
$title = '/';
if ($drequest->getPath() !== null) {
$title = nonempty(basename($drequest->getPath()), '/');
}
$empty_result = null; $empty_result = null;
$browse_panel = null; $browse_panel = null;
if (!$results->isValidResults()) { if (!$results->isValidResults()) {
@ -303,7 +308,6 @@ final class DiffusionBrowseController extends DiffusionController {
->setPaths($results->getPaths()) ->setPaths($results->getPaths())
->setUser($request->getUser()); ->setUser($request->getUser());
$title = nonempty(basename($drequest->getPath()), '/');
$icon = 'fa-folder-open'; $icon = 'fa-folder-open';
$browse_header = $this->buildPanelHeaderView($title, $icon); $browse_header = $this->buildPanelHeaderView($title, $icon);
@ -351,7 +355,7 @@ final class DiffusionBrowseController extends DiffusionController {
return $this->newPage() return $this->newPage()
->setTitle(array( ->setTitle(array(
nonempty(basename($drequest->getPath()), '/'), $title,
$repository->getDisplayName(), $repository->getDisplayName(),
)) ))
->setCrumbs($crumbs) ->setCrumbs($crumbs)

View file

@ -27,8 +27,11 @@ final class DiffusionCommitController extends DiffusionController {
// If this page is being accessed via "/source/xyz/commit/...", redirect // If this page is being accessed via "/source/xyz/commit/...", redirect
// to the canonical URI. // to the canonical URI.
$has_callsign = strlen($request->getURIData('repositoryCallsign')); $repo_callsign = $request->getURIData('repositoryCallsign');
$has_id = strlen($request->getURIData('repositoryID')); $has_callsign = $repo_callsign !== null && strlen($repo_callsign);
$repo_id = $request->getURIData('repositoryID');
$has_id = $repo_id !== null && strlen($repo_id);
if (!$has_callsign && !$has_id) { if (!$has_callsign && !$has_id) {
$canonical_uri = $repository->getCommitURI($commit_identifier); $canonical_uri = $repository->getCommitURI($commit_identifier);
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
@ -922,7 +925,7 @@ final class DiffusionCommitController extends DiffusionController {
private function linkBugtraq($corpus) { private function linkBugtraq($corpus) {
$url = PhabricatorEnv::getEnvConfig('bugtraq.url'); $url = PhabricatorEnv::getEnvConfig('bugtraq.url');
if (!strlen($url)) { if ($url === null || !strlen($url)) {
return $corpus; return $corpus;
} }

View file

@ -97,19 +97,19 @@ abstract class DiffusionController extends PhabricatorController {
AphrontRequest $request) { AphrontRequest $request) {
$short_name = $request->getURIData('repositoryShortName'); $short_name = $request->getURIData('repositoryShortName');
if (strlen($short_name)) { if ($short_name !== null && strlen($short_name)) {
// If the short name ends in ".git", ignore it. // If the short name ends in ".git", ignore it.
$short_name = preg_replace('/\\.git\z/', '', $short_name); $short_name = preg_replace('/\\.git\z/', '', $short_name);
return $short_name; return $short_name;
} }
$identifier = $request->getURIData('repositoryCallsign'); $identifier = $request->getURIData('repositoryCallsign');
if (strlen($identifier)) { if ($identifier !== null && strlen($identifier)) {
return $identifier; return $identifier;
} }
$id = $request->getURIData('repositoryID'); $id = $request->getURIData('repositoryID');
if (strlen($id)) { if ($id !== null && strlen($id)) {
return (int)$id; return (int)$id;
} }
@ -265,7 +265,10 @@ abstract class DiffusionController extends PhabricatorController {
protected function renderPathLinks(DiffusionRequest $drequest, $action) { protected function renderPathLinks(DiffusionRequest $drequest, $action) {
$path = $drequest->getPath(); $path = $drequest->getPath();
$path_parts = array_filter(explode('/', trim($path, '/'))); $path_parts = array();
if ($path !== null && strlen($path)) {
$path_parts = array_filter(explode('/', trim($path, '/')));
}
$divider = phutil_tag( $divider = phutil_tag(
'span', 'span',

View file

@ -50,7 +50,8 @@ final class DiffusionHistoryController extends DiffusionController {
// ancestors appropriately, but this would currrently be prohibitively // ancestors appropriately, but this would currrently be prohibitively
// expensive in the general case. // expensive in the general case.
$show_graph = !strlen($drequest->getPath()); $show_graph = ($drequest->getPath() === null
|| !strlen($drequest->getPath()));
if ($show_graph) { if ($show_graph) {
$history_list $history_list
->setParents($history_results['parents']) ->setParents($history_results['parents'])
@ -98,7 +99,7 @@ final class DiffusionHistoryController extends DiffusionController {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$no_path = !strlen($drequest->getPath()); $no_path = $drequest->getPath() === null || !strlen($drequest->getPath());
if ($no_path) { if ($no_path) {
$header_text = pht('History'); $header_text = pht('History');
} else { } else {

View file

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

View file

@ -183,11 +183,13 @@ final class DiffusionServeController extends DiffusionController {
// won't prompt users who provide a username but no password otherwise. // won't prompt users who provide a username but no password otherwise.
// See T10797 for discussion. // See T10797 for discussion.
$have_user = strlen(idx($_SERVER, 'PHP_AUTH_USER')); $http_user = idx($_SERVER, 'PHP_AUTH_USER');
$have_pass = strlen(idx($_SERVER, 'PHP_AUTH_PW')); $http_pass = idx($_SERVER, 'PHP_AUTH_PW');
$have_user = $http_user !== null && strlen($http_user);
$have_pass = $http_pass !== null && strlen($http_pass);
if ($have_user && $have_pass) { if ($have_user && $have_pass) {
$username = $_SERVER['PHP_AUTH_USER']; $username = $http_user;
$password = new PhutilOpaqueEnvelope($_SERVER['PHP_AUTH_PW']); $password = new PhutilOpaqueEnvelope($http_pass);
// Try Git LFS auth first since we can usually reject it without doing // Try Git LFS auth first since we can usually reject it without doing
// any queries, since the username won't match the one we expect or the // any queries, since the username won't match the one we expect or the
@ -524,9 +526,15 @@ final class DiffusionServeController extends DiffusionController {
break; break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$cmd = $request->getStr('cmd'); $cmd = $request->getStr('cmd');
if ($cmd === null) {
return false;
}
if ($cmd == 'batch') { if ($cmd == 'batch') {
$cmds = idx($this->getMercurialArguments(), 'cmds'); $cmds = idx($this->getMercurialArguments(), 'cmds');
return DiffusionMercurialWireProtocol::isReadOnlyBatchCommand($cmds); if ($cmds !== null) {
return DiffusionMercurialWireProtocol::isReadOnlyBatchCommand(
$cmds);
}
} }
return DiffusionMercurialWireProtocol::isReadOnlyCommand($cmd); return DiffusionMercurialWireProtocol::isReadOnlyCommand($cmd);
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
@ -878,10 +886,29 @@ final class DiffusionServeController extends DiffusionController {
} }
$args_raw[] = $_SERVER[$header]; $args_raw[] = $_SERVER[$header];
} }
$args_raw = implode('', $args_raw);
return id(new PhutilQueryStringParser()) if ($args_raw) {
->parseQueryString($args_raw); $args_raw = implode('', $args_raw);
return id(new PhutilQueryStringParser())
->parseQueryString($args_raw);
}
// Sometimes arguments come in via the query string. Note that this will
// not handle multi-value entries e.g. "a[]=1,a[]=2" however it's unclear
// whether or how the mercurial protocol should handle this.
$query = idx($_SERVER, 'QUERY_STRING', '');
$query_pairs = id(new PhutilQueryStringParser())
->parseQueryString($query);
foreach ($query_pairs as $key => $value) {
// Filter out private/internal keys as well as the command itself.
if (strncmp($key, '__', 2) && $key != 'cmd') {
$args_raw[$key] = $value;
}
}
// TODO: Arguments can also come in via request body for POST requests. The
// body would be all arguments, url-encoded.
return $args_raw;
} }
private function formatMercurialArguments($command, array $arguments) { private function formatMercurialArguments($command, array $arguments) {

View file

@ -25,7 +25,9 @@ final class DiffusionTagListController extends DiffusionController {
'offset' => $pager->getOffset(), 'offset' => $pager->getOffset(),
); );
if (strlen($drequest->getSymbolicCommit())) { if ($drequest->getSymbolicCommit() !== null
&& strlen($drequest->getSymbolicCommit())) {
$is_commit = true; $is_commit = true;
$params['commit'] = $drequest->getSymbolicCommit(); $params['commit'] = $drequest->getSymbolicCommit();
} else { } else {

View file

@ -131,6 +131,13 @@ final class DiffusionCommitRef extends Phobject {
} }
private function formatUser($name, $email) { private function formatUser($name, $email) {
if ($name === null) {
$name = '';
}
if ($email === null) {
$email = '';
}
if (strlen($name) && strlen($email)) { if (strlen($name) && strlen($email)) {
return "{$name} <{$email}>"; return "{$name} <{$email}>";
} else if (strlen($email)) { } else if (strlen($email)) {

View file

@ -87,7 +87,7 @@ final class DiffusionDocumentRenderingEngine
$ref->setSymbolMetadata($this->getSymbolMetadata()); $ref->setSymbolMetadata($this->getSymbolMetadata());
$coverage = $drequest->loadCoverage(); $coverage = $drequest->loadCoverage();
if (strlen($coverage)) { if ($coverage !== null && strlen($coverage)) {
$ref->addCoverage($coverage); $ref->addCoverage($coverage);
} }
} }

View file

@ -1133,7 +1133,7 @@ final class DiffusionCommitHookEngine extends Phobject {
->setHookWait(phutil_microseconds_since($hook_start)); ->setHookWait(phutil_microseconds_since($hook_start));
$identifier = $this->getRequestIdentifier(); $identifier = $this->getRequestIdentifier();
if (strlen($identifier)) { if ($identifier !== null && strlen($identifier)) {
$event->setRequestIdentifier($identifier); $event->setRequestIdentifier($identifier);
} }

View file

@ -92,7 +92,10 @@ abstract class DiffusionFileFutureQuery
$drequest = $this->getRequest(); $drequest = $this->getRequest();
$name = basename($drequest->getPath()); $name = '';
if ($drequest->getPath() !== null) {
$name = basename($drequest->getPath());
}
$relative_ttl = phutil_units('48 hours in seconds'); $relative_ttl = phutil_units('48 hours in seconds');
try { try {

View file

@ -32,8 +32,12 @@ final class DiffusionLowLevelMercurialPathsQuery
$hg_paths_command = 'locate --print0 --rev %s -I %s'; $hg_paths_command = 'locate --print0 --rev %s -I %s';
} }
$match_against = trim($path, '/'); if ($path !== null) {
$prefix = trim('./'.$match_against, '/'); $match_against = trim($path, '/');
$prefix = trim('./'.$match_against, '/');
} else {
$prefix = '.';
}
list($entire_manifest) = $repository->execxLocalCommand( list($entire_manifest) = $repository->execxLocalCommand(
$hg_paths_command, $hg_paths_command,
hgsprintf('%s', $commit), hgsprintf('%s', $commit),

View file

@ -48,6 +48,10 @@ final class DiffusionPathIDQuery extends Phobject {
*/ */
public static function normalizePath($path) { public static function normalizePath($path) {
if ($path === null) {
return '/';
}
// Normalize to single slashes, e.g. "///" => "/". // Normalize to single slashes, e.g. "///" => "/".
$path = preg_replace('@[/]{2,}@', '/', $path); $path = preg_replace('@[/]{2,}@', '/', $path);

View file

@ -35,7 +35,7 @@ final class DiffusionGitRawDiffQuery extends DiffusionRawDiffQuery {
} }
$path = $drequest->getPath(); $path = $drequest->getPath();
if (!strlen($path)) { if ($path === null || !strlen($path)) {
$path = '.'; $path = '.';
} }

View file

@ -3,7 +3,7 @@
final class DiffusionGitRequest extends DiffusionRequest { final class DiffusionGitRequest extends DiffusionRequest {
protected function isStableCommit($symbol) { protected function isStableCommit($symbol) {
return preg_match('/^[a-f0-9]{40}\z/', $symbol); return $symbol !== null && preg_match('/^[a-f0-9]{40}\z/', $symbol);
} }
public function getBranch() { public function getBranch() {

View file

@ -3,7 +3,7 @@
final class DiffusionMercurialRequest extends DiffusionRequest { final class DiffusionMercurialRequest extends DiffusionRequest {
protected function isStableCommit($symbol) { protected function isStableCommit($symbol) {
return preg_match('/^[a-f0-9]{40}\z/', $symbol); return $symbol !== null && preg_match('/^[a-f0-9]{40}\z/', $symbol);
} }
public function getBranch() { public function getBranch() {

View file

@ -3,7 +3,7 @@
final class DiffusionSvnRequest extends DiffusionRequest { final class DiffusionSvnRequest extends DiffusionRequest {
protected function isStableCommit($symbol) { protected function isStableCommit($symbol) {
return preg_match('/^[1-9]\d*\z/', $symbol); return $symbol !== null && preg_match('/^[1-9]\d*\z/', $symbol);
} }
protected function didInitialize() { protected function didInitialize() {

View file

@ -15,9 +15,13 @@ final class DiffusionBrowseTableView extends DiffusionView {
$repository = $request->getRepository(); $repository = $request->getRepository();
require_celerity_resource('diffusion-css'); require_celerity_resource('diffusion-css');
$base_path = trim($request->getPath(), '/'); if ($request->getPath() !== null) {
if ($base_path) { $base_path = trim($request->getPath(), '/');
$base_path = $base_path.'/'; if ($base_path) {
$base_path = $base_path.'/';
}
} else {
$base_path = '';
} }
$need_pull = array(); $need_pull = array();

View file

@ -71,7 +71,7 @@ abstract class DiffusionView extends AphrontView {
$display_name = idx($details, 'name'); $display_name = idx($details, 'name');
unset($details['name']); unset($details['name']);
if (strlen($display_name)) { if ($display_name !== null && strlen($display_name)) {
$display_name = phutil_tag( $display_name = phutil_tag(
'span', 'span',
array( array(

View file

@ -81,10 +81,15 @@ final class DivinerAtom extends Phobject {
public function setDocblockRaw($docblock_raw) { public function setDocblockRaw($docblock_raw) {
$this->docblockRaw = $docblock_raw; $this->docblockRaw = $docblock_raw;
$parser = new PhutilDocblockParser(); if ($docblock_raw !== null) {
list($text, $meta) = $parser->parse($docblock_raw); $parser = new PhutilDocblockParser();
$this->docblockText = $text; list($text, $meta) = $parser->parse($docblock_raw);
$this->docblockMeta = $meta; $this->docblockText = $text;
$this->docblockMeta = $meta;
} else {
$this->docblockText = null;
$this->docblockMeta = null;
}
return $this; return $this;
} }

View file

@ -133,7 +133,7 @@ final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$this->phids); $this->phids);
} }
if (strlen($this->nameLike)) { if ($this->nameLike !== null && strlen($this->nameLike)) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'name LIKE %~', 'name LIKE %~',
@ -147,7 +147,7 @@ final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$this->names); $this->names);
} }
if (strlen($this->namePrefix)) { if ($this->namePrefix !== null && strlen($this->namePrefix)) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'name LIKE %>', 'name LIKE %>',

View file

@ -182,7 +182,7 @@ final class DivinerLiveSymbol extends DivinerDAO
public function setTitle($value) { public function setTitle($value) {
$this->writeField('title', $value); $this->writeField('title', $value);
if (strlen($value)) { if ($value !== null && strlen($value)) {
$slug = DivinerAtomRef::normalizeTitleString($value); $slug = DivinerAtomRef::normalizeTitleString($value);
$hash = PhabricatorHash::digestForIndex($slug); $hash = PhabricatorHash::digestForIndex($slug);
$this->titleSlugHash = $hash; $this->titleSlugHash = $hash;

View file

@ -194,7 +194,7 @@ final class DivinerGenerateWorkflow extends DivinerWorkflow {
$identifier = $args->getArg('repository'); $identifier = $args->getArg('repository');
$repository = null; $repository = null;
if (strlen($identifier)) { if ($identifier !== null && strlen($identifier)) {
$repository = id(new PhabricatorRepositoryQuery()) $repository = id(new PhabricatorRepositoryQuery())
->setViewer(PhabricatorUser::getOmnipotentUser()) ->setViewer(PhabricatorUser::getOmnipotentUser())
->withIdentifiers(array($identifier)) ->withIdentifiers(array($identifier))

View file

@ -183,11 +183,11 @@ final class PhabricatorFilesComposeAvatarBuiltinFile
'image/png'); 'image/png');
} }
private static function rgba2gd($rgba) { private static function rgba2gd(array $rgba) {
$r = $rgba[0]; $r = (int)$rgba[0];
$g = $rgba[1]; $g = (int)$rgba[1];
$b = $rgba[2]; $b = (int)$rgba[2];
$a = $rgba[3]; $a = (int)$rgba[3];
$a = (1 - $a) * 255; $a = (1 - $a) * 255;
return ($a << 24) | ($r << 16) | ($g << 8) | $b; return ($a << 24) | ($r << 16) | ($g << 8) | $b;
} }

View file

@ -65,7 +65,7 @@ final class FileAllocateConduitAPIMethod
->executeOne(); ->executeOne();
} }
if (strlen($name) && !$hash && !$file) { if ($name !== null && strlen($name) && !$hash && !$file) {
if ($length > PhabricatorFileStorageEngine::getChunkThreshold()) { if ($length > PhabricatorFileStorageEngine::getChunkThreshold()) {
// If we don't have a hash, but this file is large enough to store in // If we don't have a hash, but this file is large enough to store in
// chunks and thus may be resumable, try to find a partially uploaded // chunks and thus may be resumable, try to find a partially uploaded

View file

@ -31,6 +31,9 @@ final class FileUploadConduitAPIMethod extends FileConduitAPIMethod {
$view_policy = $request->getValue('viewPolicy'); $view_policy = $request->getValue('viewPolicy');
$data = $request->getValue('data_base64'); $data = $request->getValue('data_base64');
if ($data === null) {
throw new Exception(pht('Field "data_base64" must be non-empty.'));
}
$data = $this->decodeBase64($data); $data = $this->decodeBase64($data);
$params = array( $params = array(

View file

@ -29,7 +29,7 @@ final class PhabricatorFileDataController extends PhabricatorFileController {
$request_kind = $request->getURIData('kind'); $request_kind = $request->getURIData('kind');
$is_download = ($request_kind === 'download'); $is_download = ($request_kind === 'download');
if (!strlen($alt) || $main_domain == $alt_domain) { if (($alt === null || !strlen($alt)) || $main_domain == $alt_domain) {
// No alternate domain. // No alternate domain.
$should_redirect = false; $should_redirect = false;
$is_alternate_domain = false; $is_alternate_domain = false;
@ -69,7 +69,7 @@ final class PhabricatorFileDataController extends PhabricatorFileController {
// an initial request for bytes 0-1 of the audio file, and things go south // an initial request for bytes 0-1 of the audio file, and things go south
// if we can't respond with a 206 Partial Content. // if we can't respond with a 206 Partial Content.
$range = $request->getHTTPHeader('range'); $range = $request->getHTTPHeader('range');
if (strlen($range)) { if ($range !== null && strlen($range)) {
list($begin, $end) = $response->parseHTTPRange($range); list($begin, $end) = $response->parseHTTPRange($range);
} }

View file

@ -20,7 +20,7 @@ final class PhabricatorFileLightboxController
return new Aphront404Response(); return new Aphront404Response();
} }
if (strlen($comment)) { if ($comment !== null && strlen($comment)) {
$xactions = array(); $xactions = array();
$xactions[] = id(new PhabricatorFileTransaction()) $xactions[] = id(new PhabricatorFileTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)

View file

@ -311,12 +311,12 @@ final class PhabricatorFileViewController extends PhabricatorFileController {
$file->getStorageHandle()); $file->getStorageHandle());
$custom_alt = $file->getCustomAltText(); $custom_alt = $file->getCustomAltText();
if (strlen($custom_alt)) { if ($custom_alt !== null && strlen($custom_alt)) {
$finfo->addProperty(pht('Custom Alt Text'), $custom_alt); $finfo->addProperty(pht('Custom Alt Text'), $custom_alt);
} }
$default_alt = $file->getDefaultAltText(); $default_alt = $file->getDefaultAltText();
if (strlen($default_alt)) { if ($default_alt !== null && strlen($default_alt)) {
$finfo->addProperty(pht('Default Alt Text'), $default_alt); $finfo->addProperty(pht('Default Alt Text'), $default_alt);
} }

View file

@ -323,7 +323,7 @@ final class PhabricatorJupyterDocumentEngine
} }
$nbformat = idx($data, 'nbformat'); $nbformat = idx($data, 'nbformat');
if (!strlen($nbformat)) { if ($nbformat == null || !strlen($nbformat)) {
throw new Exception( throw new Exception(
pht( pht(
'This document is missing an "nbformat" field. Jupyter notebooks '. 'This document is missing an "nbformat" field. Jupyter notebooks '.

View file

@ -60,12 +60,12 @@ abstract class PhabricatorDocumentRenderingEngine
} }
$encode_setting = $request->getStr('encode'); $encode_setting = $request->getStr('encode');
if (strlen($encode_setting)) { if (phutil_nonempty_string($encode_setting)) {
$engine->setEncodingConfiguration($encode_setting); $engine->setEncodingConfiguration($encode_setting);
} }
$highlight_setting = $request->getStr('highlight'); $highlight_setting = $request->getStr('highlight');
if (strlen($highlight_setting)) { if (phutil_nonempty_string($highlight_setting)) {
$engine->setHighlightingConfiguration($highlight_setting); $engine->setHighlightingConfiguration($highlight_setting);
} }
@ -208,12 +208,12 @@ abstract class PhabricatorDocumentRenderingEngine
$this->activeEngine = $engine; $this->activeEngine = $engine;
$encode_setting = $request->getStr('encode'); $encode_setting = $request->getStr('encode');
if (strlen($encode_setting)) { if (phutil_nonempty_string($encode_setting)) {
$engine->setEncodingConfiguration($encode_setting); $engine->setEncodingConfiguration($encode_setting);
} }
$highlight_setting = $request->getStr('highlight'); $highlight_setting = $request->getStr('highlight');
if (strlen($highlight_setting)) { if (phutil_nonempty_string($highlight_setting)) {
$engine->setHighlightingConfiguration($highlight_setting); $engine->setHighlightingConfiguration($highlight_setting);
} }

View file

@ -31,11 +31,11 @@ final class PhabricatorS3FileStorageEngine
$endpoint = PhabricatorEnv::getEnvConfig('amazon-s3.endpoint'); $endpoint = PhabricatorEnv::getEnvConfig('amazon-s3.endpoint');
$region = PhabricatorEnv::getEnvConfig('amazon-s3.region'); $region = PhabricatorEnv::getEnvConfig('amazon-s3.region');
return (strlen($bucket) && return ($bucket !== null && strlen($bucket) &&
strlen($access_key) && $access_key !== null && strlen($access_key) &&
strlen($secret_key) && $secret_key !== null && strlen($secret_key) &&
strlen($endpoint) && $endpoint !== null && strlen($endpoint) &&
strlen($region)); $region !== null && strlen($region));
} }
@ -57,7 +57,7 @@ final class PhabricatorS3FileStorageEngine
$parts[] = 'phabricator'; $parts[] = 'phabricator';
$instance_name = PhabricatorEnv::getEnvConfig('cluster.instance'); $instance_name = PhabricatorEnv::getEnvConfig('cluster.instance');
if (strlen($instance_name)) { if ($instance_name !== null && strlen($instance_name)) {
$parts[] = $instance_name; $parts[] = $instance_name;
} }

View file

@ -197,7 +197,7 @@ final class PhabricatorEmbedFileRemarkupRule
$alt = $options['alt']; $alt = $options['alt'];
} }
if (!strlen($alt)) { if ($alt === null || !strlen($alt)) {
$alt = $file->getAltText(); $alt = $file->getAltText();
} }
@ -346,6 +346,9 @@ final class PhabricatorEmbedFileRemarkupRule
} }
private function parseDimension($string) { private function parseDimension($string) {
if ($string === null || !strlen($string)) {
return null;
}
$string = trim($string); $string = trim($string);
if (preg_match('/^(?:\d*\\.)?\d+%?$/', $string)) { if (preg_match('/^(?:\d*\\.)?\d+%?$/', $string)) {

View file

@ -49,7 +49,8 @@ final class PhabricatorImageRemarkupRule extends PhutilRemarkupRule {
$args += $defaults; $args += $defaults;
if (!strlen($args['uri'])) { $uri_arg = $args['uri'];
if ($uri_arg === null || !strlen($uri_arg)) {
return $matches[0]; return $matches[0];
} }
@ -57,9 +58,9 @@ final class PhabricatorImageRemarkupRule extends PhutilRemarkupRule {
// validate it more carefully before proxying it, but if whatever the user // validate it more carefully before proxying it, but if whatever the user
// has typed isn't even close, just decline to activate the rule behavior. // has typed isn't even close, just decline to activate the rule behavior.
try { try {
$uri = new PhutilURI($args['uri']); $uri = new PhutilURI($uri_arg);
if (!strlen($uri->getProtocol())) { if ($uri->getProtocol() === null || !strlen($uri->getProtocol())) {
return $matches[0]; return $matches[0];
} }

View file

@ -288,7 +288,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
// update the parent file if a MIME type hasn't been provided. This matters // update the parent file if a MIME type hasn't been provided. This matters
// for large media files like video. // for large media files like video.
$mime_type = idx($params, 'mime-type'); $mime_type = idx($params, 'mime-type');
if (!strlen($mime_type)) { if ($mime_type === null || !strlen($mime_type)) {
$file->setMimeType('application/octet-stream'); $file->setMimeType('application/octet-stream');
} }
@ -856,7 +856,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
// instance identity in the path allows us to distinguish between requests // instance identity in the path allows us to distinguish between requests
// originating from different instances but served through the same CDN. // originating from different instances but served through the same CDN.
$instance = PhabricatorEnv::getEnvConfig('cluster.instance'); $instance = PhabricatorEnv::getEnvConfig('cluster.instance');
if (strlen($instance)) { if ($instance !== null && strlen($instance)) {
$parts[] = '@'.$instance; $parts[] = '@'.$instance;
} }
@ -903,7 +903,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
$parts[] = 'xform'; $parts[] = 'xform';
$instance = PhabricatorEnv::getEnvConfig('cluster.instance'); $instance = PhabricatorEnv::getEnvConfig('cluster.instance');
if (strlen($instance)) { if ($instance !== null && strlen($instance)) {
$parts[] = '@'.$instance; $parts[] = '@'.$instance;
} }
@ -1278,7 +1278,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
public function getAltText() { public function getAltText() {
$alt = $this->getCustomAltText(); $alt = $this->getCustomAltText();
if (strlen($alt)) { if ($alt !== null && strlen($alt)) {
return $alt; return $alt;
} }
@ -1309,7 +1309,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
$parts = array(); $parts = array();
$name = $this->getName(); $name = $this->getName();
if (strlen($name)) { if ($name !== null && strlen($name)) {
$parts[] = $name; $parts[] = $name;
} }

View file

@ -67,7 +67,7 @@ final class PhabricatorGlobalUploadTargetView extends AphrontView {
require_celerity_resource('global-drag-and-drop-css'); require_celerity_resource('global-drag-and-drop-css');
$hint_text = $this->getHintText(); $hint_text = $this->getHintText();
if (!strlen($hint_text)) { if ($hint_text === null || !strlen($hint_text)) {
$hint_text = "\xE2\x87\xAA ".pht('Drop Files to Upload'); $hint_text = "\xE2\x87\xAA ".pht('Drop Files to Upload');
} }

View file

@ -27,12 +27,12 @@ final class PhabricatorFileAltTextTransaction
$old_value = $this->getOldValue(); $old_value = $this->getOldValue();
$new_value = $this->getNewValue(); $new_value = $this->getNewValue();
if (!strlen($old_value)) { if ($old_value == null || !strlen($old_value)) {
return pht( return pht(
'%s set the alternate text for this file to %s.', '%s set the alternate text for this file to %s.',
$this->renderAuthor(), $this->renderAuthor(),
$this->renderNewValue()); $this->renderNewValue());
} else if (!strlen($new_value)) { } else if ($new_value === null || !strlen($new_value)) {
return pht( return pht(
'%s removed the alternate text for this file (was %s).', '%s removed the alternate text for this file (was %s).',
$this->renderAuthor(), $this->renderAuthor(),
@ -50,13 +50,13 @@ final class PhabricatorFileAltTextTransaction
$old_value = $this->getOldValue(); $old_value = $this->getOldValue();
$new_value = $this->getNewValue(); $new_value = $this->getNewValue();
if (!strlen($old_value)) { if ($old_value === null || !strlen($old_value)) {
return pht( return pht(
'%s set the alternate text for %s to %s.', '%s set the alternate text for %s to %s.',
$this->renderAuthor(), $this->renderAuthor(),
$this->renderObject(), $this->renderObject(),
$this->renderNewValue()); $this->renderNewValue());
} else if (!strlen($new_value)) { } else if ($new_value === null || !strlen($new_value)) {
return pht( return pht(
'%s removed the alternate text for %s (was %s).', '%s removed the alternate text for %s (was %s).',
$this->renderAuthor(), $this->renderAuthor(),

View file

@ -515,7 +515,7 @@ EOREMARKUP
} }
} }
if (!strlen($receiver_name)) { if ($receiver_name === null || !strlen($receiver_name)) {
throw new Exception( throw new Exception(
pht( pht(
'Call omits required "receiver" parameter. Specify the PHID '. 'Call omits required "receiver" parameter. Specify the PHID '.
@ -523,7 +523,7 @@ EOREMARKUP
} }
$message_type = $request->getValue('type'); $message_type = $request->getValue('type');
if (!strlen($message_type)) { if ($message_type === null || !strlen($message_type)) {
throw new Exception( throw new Exception(
pht( pht(
'Call omits required "type" parameter. Specify the type of '. 'Call omits required "type" parameter. Specify the type of '.

View file

@ -103,7 +103,7 @@ final class HarbormasterBuildPlanEditEngine
$key); $key);
$behavior_option = $object->getPlanProperty($storage_key); $behavior_option = $object->getPlanProperty($storage_key);
if (!strlen($behavior_option)) { if ($behavior_option === null || !strlen($behavior_option)) {
$behavior_option = $behavior->getPlanOption($object)->getKey(); $behavior_option = $behavior->getPlanOption($object)->getKey();
} }

View file

@ -35,7 +35,7 @@ final class HeraldTranscriptPHIDType extends PhabricatorPHIDType {
$id = $xscript->getID(); $id = $xscript->getID();
$handle->setName(pht('Transcript %s', $id)); $handle->setName(pht('Transcript %s', $id));
$handle->setURI("/herald/transcript/${id}/"); $handle->setURI("/herald/transcript/{$id}/");
} }
} }

Some files were not shown because too many files have changed in this diff Show more