Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exceptions trying to browse Diffusion repository code
ClosedPublic

Authored by aklapper on Jun 12 2023, 00:26.

Details

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. Phorge adopts phutil_nonempty_string() as a replacement.

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

EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(head=master, ref.master=97e163187418), phorge(head=diffusionBrowseCode, ref.master=108cbcd09bd3, ref.diffusionBrowseCode=108cbcd09bd3)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/applications/diffusion/controller/DiffusionBrowseController.php:25]
EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(head=master, ref.master=97e163187418), phorge(head=diffusionBrowseCode, ref.master=108cbcd09bd3, ref.diffusionBrowseCode=108cbcd09bd3)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php:40]

Closes T15462

Test Plan

After applying these two changes, get next expected exceptions about RuntimeException: file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated and CommandException: Command failed with error #128! fatal: detected dubious ownership in repository at '/var/repo/1', but no RuntimeException about strlen() anymore.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

speck requested changes to this revision.Jun 12 2023, 00:46
speck added inline comments.
src/applications/diffusion/controller/DiffusionBrowseController.php
25

I think this would prevent beeping for “0” and possibly “null”, instead should use nonempty string

This revision now requires changes to proceed.Jun 12 2023, 00:46
src/applications/diffusion/controller/DiffusionBrowseController.php
25

@speck: I didn't use phutil_nonempty_string as my naive interpretation was that getStr comes from https://we.phorge.it/source/phorge/browse/master/src/aphront/AphrontRequest.php$209 allowing to return null as default. I'm happy to be wrong as I'm not familiar with the code base.

src/applications/diffusion/controller/DiffusionBrowseController.php
25

That’s true, but I think the raw check of if($grep) would return false if the user entered the valid values of “0” or “null”

Use phutil_nonempty_string instead as requested

This revision is now accepted and ready to land.Jun 12 2023, 01:44