From 5405134fa5db77bfdc0f5dbc55ed07134a60799a Mon Sep 17 00:00:00 2001 From: Valerio Bozzolan Date: Thu, 25 May 2023 16:10:21 +0200 Subject: [PATCH] Fix PHP 8.1 "strlen(null)" exception which can block repository imports Summary: `strlen()` was used in Phabricator to check if a generic value is a non-empty string. This behavior is deprecated since PHP 8.1. Interestingly, in upstream they started fixing this yesterday, with just this minimal change: https://secure.phabricator.com/rPf6214f060e780ecf7b565c5a0edbd28d85c03275#C11580NL1139 Premising counting the length of a string just to answer the question "is this empty?" may be overkill, but premising that adopting stuff like phutil_nonempty_string() could be too risky, we just do an explicit cast to string, to answer the question "Is this string empty?" just like it was done under the hood by the strlen() function. In short, this is probably nice and more readable than upstream (but not a competition). Closes T15370 Test Plan: - create a Mercurial repository - push some things - it should conclude the import (or at least unlock a different Exception) Reviewers: O1 Blessed Committers, speck, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: avivey, amit, speck, tobiaswiese, Matthew, Cigaryno Maniphest Tasks: T15370 Differential Revision: https://we.phorge.it/D25204 --- .../search/engine/PhabricatorApplicationSearchEngine.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index effb20eb34..076a9a1e52 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -1137,7 +1137,8 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { $viewer = $this->requireViewer(); $query_key = $request->getValue('queryKey'); - if (!strlen($query_key)) { + $is_empty_query_key = phutil_string_cast($query_key) === ''; + if ($is_empty_query_key) { $saved_query = new PhabricatorSavedQuery(); } else if ($this->isBuiltinQuery($query_key)) { $saved_query = $this->buildSavedQueryFromBuiltin($query_key); -- 2.51.2