Page MenuHomePhorge

PHP 8.1: fixes for strlen() not accepting NULL anymore, part 3
AbandonedPublic

Authored by valerio.bozzolan on Apr 1 2023, 09:55.
Referenced Files
Unknown Object (File)
Sun, Apr 14, 13:34
Unknown Object (File)
Sat, Apr 13, 10:34
Unknown Object (File)
Sat, Apr 13, 08:39
Unknown Object (File)
Sat, Apr 13, 08:37
Unknown Object (File)
Fri, Apr 12, 19:05
Unknown Object (File)
Thu, Apr 11, 14:20
Unknown Object (File)
Wed, Apr 10, 21:16
Unknown Object (File)
Sun, Apr 7, 08:51

Details

Summary

This is a fix for PHP 8.1 deprecation of strlen(NULL), for these Phorge components:

  • src/view
  • src/infrastructure (partial, needs more patches)

The strlen() was used in Phabricator to check if a generic value was a non-empty string.
For this reason, Phorge adopts phutil_nonempty_string() that checks that.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If your phutil_nonempty_string() throws an exception, just
report it to Phorge to evaluate and fix together that specific corner case.

Ref T15190
Ref T15064

Test Plan
  • check with big eyes that there are no obvious typos

Diff Detail

Repository
rP Phorge
Branch
arcpatch-D25106
Lint
Lint Passed
SeverityLocationCodeMessage
Advicesrc/infrastructure/export/field/PhabricatorOptionExportField.php:19XHP16TODO Comment
Unit
Tests Passed
Build Status
Buildable 221
Build 221: arc lint + arc unit

Event Timeline

As usual, the risk of this change is that exceptions may occur due to
really weird stuff coming in as input. In any case, if it happens,
it must be evaluated on a case-by-case basis, because in this case,
the previously present code (strlen) didn't make sense anyway either.

valerio.bozzolan retitled this revision from PHP 8.2: fixes for strlen() not accepting NULL anymore, part 3 to PHP 8.1: fixes for strlen() not accepting NULL anymore, part 3.Apr 1 2023, 13:08
valerio.bozzolan edited the summary of this revision. (Show Details)

fix AphrontFileResponse#setDownload() that had weird corner-cases

src/aphront/response/AphrontFileResponse.php
22

That above check was introduced by this commit:

rP96ae4ba13acb: PHP 8.1: fixes for strlen() not accepting NULL anymore, part 2

But it's too much strict. I have double-checked and this deserves more inline documentation. See on the right.

I just added some comments, and a strong default.

47

Also this method ↓ deserved an inline comment to show that it can return mixed stuff.

140
IMPORTANT: this cannot be used as-is, since getDownload() returns mixed stuff by design it seems.
valerio.bozzolan added inline comments.
src/infrastructure/log/PhabricatorSSHLog.php
38

This replacement has sense since everything from getenv() should be a string and we should report otherwise.

src/infrastructure/management/PhabricatorManagementWorkflow.php
17

This check has sense since then we use strtotime($time) so we really want a string, and we should report alien stuff.

src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
2452

This check has sense since then we want to count length in bytes, so a string is necessary.

src/infrastructure/ssh/PhabricatorSSHWorkflow.php
104

This check has sense since we want a string and we want to report alien values from getenv().