1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 02:02:41 +01:00

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
This commit is contained in:
Valerio Bozzolan 2023-05-25 16:10:21 +02:00
parent 82e7f30a82
commit 5405134fa5

View file

@ -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);