Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2697467
D25106.1734934223.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
20 KB
Referenced Files
None
Subscribers
None
D25106.1734934223.diff
View Options
diff --git a/src/aphront/response/AphrontFileResponse.php b/src/aphront/response/AphrontFileResponse.php
--- a/src/aphront/response/AphrontFileResponse.php
+++ b/src/aphront/response/AphrontFileResponse.php
@@ -18,14 +18,38 @@
return $this;
}
+ /**
+ * Set the download filename
+ *
+ * @param $download mixed
+ * @return self
+ */
public function setDownload($download) {
- if (!phutil_nonempty_string($download)) {
- $download = 'untitled';
+ // Known usage:
+ // setDownload(null) -> no download - default
+ // setDownload(false) -> no download - expected
+ // setDownload(true) -> yes named 'untitled' - expected
+ // setDownload('foo.ical') -> yes named 'foo.ical' - expected
+ // setDownload('') -> no download - please avoid
+ // setDownload(0) -> no download - please avoid
+ // setDownload(1) -> yes named 'untitled' - please avoid
+ if ($download) {
+
+ // If you want a download, but you have no idea
+ // about the title, let's choose for you
+ if (!is_string($download)) {
+ $download = 'untitled';
+ }
}
$this->download = $download;
return $this;
}
+ /**
+ * Get the download filename
+ *
+ * @return mixed
+ */
public function getDownload() {
return $this->download;
}
@@ -113,7 +137,7 @@
$headers[] = array('Content-Length', $content_len);
}
- if (strlen($this->getDownload())) {
+ if (phutil_nonempty_string($this->getDownload())) {
$headers[] = array('X-Download-Options', 'noopen');
$filename = $this->getDownload();
diff --git a/src/infrastructure/cluster/PhabricatorDatabaseRef.php b/src/infrastructure/cluster/PhabricatorDatabaseRef.php
--- a/src/infrastructure/cluster/PhabricatorDatabaseRef.php
+++ b/src/infrastructure/cluster/PhabricatorDatabaseRef.php
@@ -393,7 +393,7 @@
if ($is_replica) {
$latency = idx($replica_status, 'Seconds_Behind_Master');
- if (!strlen($latency)) {
+ if (!phutil_nonempty_string($latency)) {
$ref->setReplicaStatus(self::REPLICATION_NOT_REPLICATING);
} else {
$latency = (int)$latency;
diff --git a/src/infrastructure/contentsource/PhabricatorUnknownContentSource.php b/src/infrastructure/contentsource/PhabricatorUnknownContentSource.php
--- a/src/infrastructure/contentsource/PhabricatorUnknownContentSource.php
+++ b/src/infrastructure/contentsource/PhabricatorUnknownContentSource.php
@@ -7,7 +7,7 @@
public function getSourceName() {
$source = $this->getSource();
- if (strlen($source)) {
+ if (phutil_nonempty_string($source)) {
return pht('Unknown ("%s")', $source);
} else {
return pht('Unknown');
diff --git a/src/infrastructure/daemon/PhutilDaemon.php b/src/infrastructure/daemon/PhutilDaemon.php
--- a/src/infrastructure/daemon/PhutilDaemon.php
+++ b/src/infrastructure/daemon/PhutilDaemon.php
@@ -295,7 +295,7 @@
}
public function didReceiveStdout($data) {
- if (!strlen($data)) {
+ if (!phutil_nonempty_string($data)) {
return '';
}
diff --git a/src/infrastructure/daemon/PhutilDaemonHandle.php b/src/infrastructure/daemon/PhutilDaemonHandle.php
--- a/src/infrastructure/daemon/PhutilDaemonHandle.php
+++ b/src/infrastructure/daemon/PhutilDaemonHandle.php
@@ -165,12 +165,12 @@
list($stdout, $stderr) = $future->read();
$future->discardBuffers();
- if (strlen($stdout)) {
+ if (phutil_nonempty_string($stdout)) {
$this->didReadStdout($stdout);
}
$stderr = trim($stderr);
- if (strlen($stderr)) {
+ if (phutil_nonempty_string($stderr)) {
foreach (phutil_split_lines($stderr, false) as $line) {
$this->logMessage('STDE', $line);
}
diff --git a/src/infrastructure/diff/prose/PhutilProseDifferenceEngine.php b/src/infrastructure/diff/prose/PhutilProseDifferenceEngine.php
--- a/src/infrastructure/diff/prose/PhutilProseDifferenceEngine.php
+++ b/src/infrastructure/diff/prose/PhutilProseDifferenceEngine.php
@@ -79,11 +79,15 @@
} else {
$old = $block['old'];
$new = $block['new'];
- if (!strlen($old) && !strlen($new)) {
+
+ $is_old_ok = phutil_nonempty_string($old);
+ $is_new_ok = phutil_nonempty_string($new);
+
+ if (!$is_old_ok && !$is_new_ok) {
// Nothing to do.
- } else if (!strlen($old)) {
+ } else if (!$is_old_ok) {
$result->addPart('+', $new);
- } else if (!strlen($new)) {
+ } else if (!$is_new_ok) {
$result->addPart('-', $old);
} else {
if ($too_large) {
diff --git a/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php b/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php
--- a/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php
+++ b/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php
@@ -139,7 +139,7 @@
$not_applicable = '-';
$coverage = $this->getCoverage();
- if (!strlen($coverage)) {
+ if (!phutil_nonempty_string($coverage)) {
return $not_applicable;
}
@@ -157,7 +157,7 @@
$not_applicable = '-';
$coverage = $this->getCoverage();
- if (!strlen($coverage)) {
+ if (!phutil_nonempty_string($coverage)) {
return $not_applicable;
}
diff --git a/src/infrastructure/export/field/PhabricatorOptionExportField.php b/src/infrastructure/export/field/PhabricatorOptionExportField.php
--- a/src/infrastructure/export/field/PhabricatorOptionExportField.php
+++ b/src/infrastructure/export/field/PhabricatorOptionExportField.php
@@ -15,11 +15,13 @@
}
public function getNaturalValue($value) {
+
+ // TODO: Remove this case since it's probably already covered
if ($value === null) {
return $value;
}
- if (!strlen($value)) {
+ if (!phutil_nonempty_string($value)) {
return null;
}
diff --git a/src/infrastructure/export/field/PhabricatorStringExportField.php b/src/infrastructure/export/field/PhabricatorStringExportField.php
--- a/src/infrastructure/export/field/PhabricatorStringExportField.php
+++ b/src/infrastructure/export/field/PhabricatorStringExportField.php
@@ -8,7 +8,7 @@
return $value;
}
- if (!strlen($value)) {
+ if (!phutil_nonempty_string($value)) {
return null;
}
diff --git a/src/infrastructure/log/PhabricatorProtocolLog.php b/src/infrastructure/log/PhabricatorProtocolLog.php
--- a/src/infrastructure/log/PhabricatorProtocolLog.php
+++ b/src/infrastructure/log/PhabricatorProtocolLog.php
@@ -24,7 +24,7 @@
}
public function didWriteBytes($bytes) {
- if (!strlen($bytes)) {
+ if (!phutil_nonempty_string($bytes)) {
return;
}
@@ -33,7 +33,7 @@
}
public function didReadBytes($bytes) {
- if (!strlen($bytes)) {
+ if (!phutil_nonempty_string($bytes)) {
return;
}
@@ -84,7 +84,7 @@
$bytes = implode('', $bytes);
- if (strlen($bytes)) {
+ if (phutil_nonempty_string($bytes)) {
$this->writeBytes($mode, $bytes);
}
}
diff --git a/src/infrastructure/log/PhabricatorSSHLog.php b/src/infrastructure/log/PhabricatorSSHLog.php
--- a/src/infrastructure/log/PhabricatorSSHLog.php
+++ b/src/infrastructure/log/PhabricatorSSHLog.php
@@ -35,7 +35,7 @@
}
$client = getenv('SSH_CLIENT');
- if (strlen($client)) {
+ if (phutil_nonempty_string($client)) {
$remote_address = head(explode(' ', $client));
$data['r'] = $remote_address;
}
diff --git a/src/infrastructure/management/PhabricatorManagementWorkflow.php b/src/infrastructure/management/PhabricatorManagementWorkflow.php
--- a/src/infrastructure/management/PhabricatorManagementWorkflow.php
+++ b/src/infrastructure/management/PhabricatorManagementWorkflow.php
@@ -14,7 +14,7 @@
}
protected function parseTimeArgument($time) {
- if (!strlen($time)) {
+ if (!phutil_nonempty_string($time)) {
return null;
}
diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
--- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
+++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
@@ -2449,7 +2449,7 @@
PhabricatorSearchNgrams $index,
$value) {
- if (strlen($value)) {
+ if (phutil_nonempty_string($value)) {
$this->ngrams[] = array(
'index' => $index,
'value' => $value,
diff --git a/src/infrastructure/ssh/PhabricatorSSHPassthruCommand.php b/src/infrastructure/ssh/PhabricatorSSHPassthruCommand.php
--- a/src/infrastructure/ssh/PhabricatorSSHPassthruCommand.php
+++ b/src/infrastructure/ssh/PhabricatorSSHPassthruCommand.php
@@ -163,7 +163,7 @@
}
$out_message = $command_channel->read();
- if (strlen($out_message)) {
+ if (phutil_nonempty_string($out_message)) {
$out_message = $this->willReadData($out_message);
if ($out_message !== null) {
$io_channel->write($out_message);
@@ -201,7 +201,7 @@
public function writeIORead($in_message) {
$in_message = $this->willWriteData($in_message);
- if (strlen($in_message)) {
+ if (phutil_nonempty_string($in_message)) {
$this->commandChannel->write($in_message);
}
}
@@ -210,7 +210,7 @@
if ($this->willWriteCallback) {
return call_user_func($this->willWriteCallback, $this, $message);
} else {
- if (strlen($message)) {
+ if (phutil_nonempty_string($message)) {
return $message;
} else {
return null;
@@ -222,7 +222,7 @@
if ($this->willReadCallback) {
return call_user_func($this->willReadCallback, $this, $message);
} else {
- if (strlen($message)) {
+ if (phutil_nonempty_string($message)) {
return $message;
} else {
return null;
diff --git a/src/infrastructure/ssh/PhabricatorSSHWorkflow.php b/src/infrastructure/ssh/PhabricatorSSHWorkflow.php
--- a/src/infrastructure/ssh/PhabricatorSSHWorkflow.php
+++ b/src/infrastructure/ssh/PhabricatorSSHWorkflow.php
@@ -101,7 +101,7 @@
public function getSSHRemoteAddress() {
$ssh_client = getenv('SSH_CLIENT');
- if (!strlen($ssh_client)) {
+ if (!phutil_nonempty_string($ssh_client)) {
return null;
}
diff --git a/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php b/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php
--- a/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php
+++ b/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php
@@ -99,7 +99,7 @@
// "port" parameter.)
if (!$ok) {
- if (strlen($call_error)) {
+ if (phutil_nonempty_string($call_error)) {
$message = pht(
'mysqli->real_connect() failed: %s',
$call_error);
@@ -180,7 +180,7 @@
if (!$result) {
$error_code = $this->getErrorCode($conn);
if (!$error_code) {
- if (strlen($err)) {
+ if (phutil_nonempty_string($err)) {
$message = $err;
} else {
$message = pht(
diff --git a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php
--- a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php
+++ b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php
@@ -38,11 +38,13 @@
* @task config
*/
public static function getStorageNamespace() {
+ // Do not use phutil_nonempty_string() in the first check,
+ // since $namespace can be false, and we should not spawn an exception
$namespace = end(self::$namespaceStack);
- if (!strlen($namespace)) {
+ if (!is_string($namespace) || $namespace === '') {
$namespace = self::getDefaultStorageNamespace();
}
- if (!strlen($namespace)) {
+ if (!phutil_nonempty_string($namespace)) {
throw new Exception(pht('No storage namespace configured!'));
}
return $namespace;
@@ -194,7 +196,7 @@
$class = substr($class, strlen($app));
}
- if (strlen($class)) {
+ if (phutil_nonempty_string($class)) {
return $app.'_'.$class;
} else {
return $app;
@@ -295,7 +297,7 @@
}
if (function_exists('mb_detect_encoding')) {
- if (strlen($encoding)) {
+ if (phutil_nonempty_string($encoding)) {
$try_encodings = array(
$encoding,
);
diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
--- a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
+++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
@@ -371,7 +371,7 @@
list($stdout, $stderr) = $future->read();
$future->discardBuffers();
- if (strlen($stderr)) {
+ if (phutil_nonempty_string($stderr)) {
fwrite(STDERR, $stderr);
}
@@ -416,7 +416,7 @@
}
private function writeData($data, $file, $is_compress, $output_file) {
- if (!strlen($data)) {
+ if (!phutil_nonempty_string($data)) {
return;
}
diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementRenamespaceWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementRenamespaceWorkflow.php
--- a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementRenamespaceWorkflow.php
+++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementRenamespaceWorkflow.php
@@ -67,7 +67,7 @@
}
$from = $args->getArg('from');
- if (!strlen($from)) {
+ if (!phutil_nonempty_string($from)) {
throw new PhutilArgumentUsageException(
pht(
'Specify namespace to rename from with %s.',
@@ -75,7 +75,7 @@
}
$to = $args->getArg('to');
- if (!strlen($to)) {
+ if (!phutil_nonempty_string($to)) {
throw new PhutilArgumentUsageException(
pht(
'Specify namespace to rename to with %s.',
diff --git a/src/infrastructure/storage/patch/PhabricatorSQLPatchList.php b/src/infrastructure/storage/patch/PhabricatorSQLPatchList.php
--- a/src/infrastructure/storage/patch/PhabricatorSQLPatchList.php
+++ b/src/infrastructure/storage/patch/PhabricatorSQLPatchList.php
@@ -288,7 +288,7 @@
case 'phase':
$phase_name = $attr_value;
- if (!strlen($phase_name)) {
+ if (!phutil_nonempty_string($phase_name)) {
throw new Exception(
pht(
'Storage patch "%s" specifies a "@phase" attribute with '.
diff --git a/src/infrastructure/util/PhabricatorHash.php b/src/infrastructure/util/PhabricatorHash.php
--- a/src/infrastructure/util/PhabricatorHash.php
+++ b/src/infrastructure/util/PhabricatorHash.php
@@ -197,7 +197,7 @@
pht('HMAC-SHA256 keys must be strings.'));
}
- if (!strlen($key)) {
+ if (!phutil_nonempty_string($key)) {
throw new Exception(
pht('HMAC-SHA256 requires a nonempty key.'));
}
diff --git a/src/infrastructure/util/password/PhabricatorPasswordHasher.php b/src/infrastructure/util/password/PhabricatorPasswordHasher.php
--- a/src/infrastructure/util/password/PhabricatorPasswordHasher.php
+++ b/src/infrastructure/util/password/PhabricatorPasswordHasher.php
@@ -388,7 +388,7 @@
*/
public static function getCurrentAlgorithmName(PhutilOpaqueEnvelope $hash) {
$raw_hash = $hash->openEnvelope();
- if (!strlen($raw_hash)) {
+ if (!phutil_nonempty_string($raw_hash)) {
return pht('None');
}
diff --git a/src/view/control/AphrontTableView.php b/src/view/control/AphrontTableView.php
--- a/src/view/control/AphrontTableView.php
+++ b/src/view/control/AphrontTableView.php
@@ -135,7 +135,7 @@
$col_classes = array();
foreach ($this->columnClasses as $key => $class) {
- if (strlen($class)) {
+ if (phutil_nonempty_string($class)) {
$col_classes[] = $class;
} else {
$col_classes[] = null;
diff --git a/src/view/layout/AphrontSideNavFilterView.php b/src/view/layout/AphrontSideNavFilterView.php
--- a/src/view/layout/AphrontSideNavFilterView.php
+++ b/src/view/layout/AphrontSideNavFilterView.php
@@ -97,12 +97,12 @@
->setName($name)
->setType($type);
- if (strlen($icon)) {
+ if (phutil_nonempty_string($icon)) {
$item->setIcon($icon);
}
- if (strlen($key)) {
+ if (phutil_nonempty_string($key)) {
$item->setKey($key);
}
diff --git a/src/view/layout/PHUICurtainPanelView.php b/src/view/layout/PHUICurtainPanelView.php
--- a/src/view/layout/PHUICurtainPanelView.php
+++ b/src/view/layout/PHUICurtainPanelView.php
@@ -38,7 +38,7 @@
$header = null;
$header_text = $this->getHeaderText();
- if (strlen($header_text)) {
+ if (phutil_nonempty_string($header_text)) {
$header = phutil_tag(
'div',
array(
diff --git a/src/view/page/PhabricatorBarePageView.php b/src/view/page/PhabricatorBarePageView.php
--- a/src/view/page/PhabricatorBarePageView.php
+++ b/src/view/page/PhabricatorBarePageView.php
@@ -97,7 +97,7 @@
if ($viewer) {
$postprocessor_key = $viewer->getUserSetting(
PhabricatorAccessibilitySetting::SETTINGKEY);
- if (strlen($postprocessor_key)) {
+ if (phutil_nonempty_string($postprocessor_key)) {
$response->setPostProcessorKey($postprocessor_key);
}
}
diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php
--- a/src/view/page/PhabricatorStandardPageView.php
+++ b/src/view/page/PhabricatorStandardPageView.php
@@ -183,12 +183,12 @@
$prefix = $this->getGlyph();
} else {
$application_name = $this->getApplicationName();
- if (strlen($application_name)) {
+ if (phutil_nonempty_string($application_name)) {
$prefix = '['.$application_name.']';
}
}
- if (strlen($prefix)) {
+ if (phutil_nonempty_string($prefix)) {
$title = $prefix.' '.$title;
}
diff --git a/src/view/page/menu/PhabricatorMainMenuView.php b/src/view/page/menu/PhabricatorMainMenuView.php
--- a/src/view/page/menu/PhabricatorMainMenuView.php
+++ b/src/view/page/menu/PhabricatorMainMenuView.php
@@ -333,7 +333,7 @@
$wordmark_text = PhabricatorCustomLogoConfigType::getLogoWordmark();
- if (!strlen($wordmark_text)) {
+ if (!phutil_nonempty_string($wordmark_text)) {
$wordmark_text = PlatformSymbols::getPlatformServerName();
}
diff --git a/src/view/phui/PHUIObjectItemView.php b/src/view/phui/PHUIObjectItemView.php
--- a/src/view/phui/PHUIObjectItemView.php
+++ b/src/view/phui/PHUIObjectItemView.php
@@ -873,7 +873,7 @@
'class' => 'phui-oi-status-icon',
);
- if (strlen($label)) {
+ if (phutil_nonempty_string($label)) {
$options['sigil'] = 'has-tooltip';
$options['meta'] = array('tip' => $label, 'size' => 300);
}
@@ -890,7 +890,7 @@
'style' => 'background-image: url('.$handle->getImageURI().')',
);
- if (strlen($label)) {
+ if (phutil_nonempty_string($label)) {
$options['sigil'] = 'has-tooltip';
$options['meta'] = array('tip' => $label, 'align' => 'E');
}
diff --git a/src/view/phui/PHUISegmentBarSegmentView.php b/src/view/phui/PHUISegmentBarSegmentView.php
--- a/src/view/phui/PHUISegmentBarSegmentView.php
+++ b/src/view/phui/PHUISegmentBarSegmentView.php
@@ -55,7 +55,7 @@
$left = sprintf('%.2f%%', $left);
$tooltip = $this->tooltip;
- if (strlen($tooltip)) {
+ if (phutil_nonempty_string($tooltip)) {
Javelin::initBehavior('phabricator-tooltips');
$sigil = 'has-tooltip';
diff --git a/src/view/phui/PHUISegmentBarView.php b/src/view/phui/PHUISegmentBarView.php
--- a/src/view/phui/PHUISegmentBarView.php
+++ b/src/view/phui/PHUISegmentBarView.php
@@ -30,7 +30,7 @@
require_celerity_resource('phui-segment-bar-view-css');
$label = $this->label;
- if (strlen($label)) {
+ if (phutil_nonempty_string($label)) {
$label = phutil_tag(
'div',
array(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 06:10 (19 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1026767
Default Alt Text
D25106.1734934223.diff (20 KB)
Attached To
Mode
D25106: PHP 8.1: fixes for strlen() not accepting NULL anymore, part 3
Attached
Detach File
Event Timeline
Log In to Comment