Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception which blocks Working Copy blueprint creation in Drydock
ClosedPublic

Authored by aklapper on May 21 2023, 08:25.

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. So, we adopt an explicit cast to string
in order to answer the question "Is this a non-empty string?" without relying on implicit
cast and deprecated things.

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

Closes T15409

Test Plan

Applied this change and afterwards, selecting "Working Copy" on /drydock/blueprint/edit/form/default/ does not show a RuntimeException on strlen() anymore. Instead, it shows a PhutilAggregateException covered in T15408.

Try also creating an integer "Custom Field" in some applications like Maniphest (maniphest.custom-field-definitions)
or in the People component (user.custom-field-definitions) etc., populating the related forms with your usual fuzzy tests.

Diff Detail

Repository
rP Phorge
Branch
blueprintAlmanacHosts (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 433
Build 433: arc lint + arc unit

Event Timeline

Thanks for this troubleshooting and this patch (again) :)

Warning: I was able to reproduce the usual nuclear implosion. I tried to populate a custom integer field from a Maniphest Task from a normal form. I tried that just because the name of this class is about FieldInt so it was a bit suspicious.

Hoping to be useful I will amend our usual replacement

replace phutil_nonempty_string() with just an explicit cast to string to answer the question "is this string non empty?"
so this works with integers as well, without crashes.

Tested, no nuclear implosions

sgtm

This revision is now accepted and ready to land.May 21 2023, 08:53
valerio.bozzolan edited the summary of this revision. (Show Details)
valerio.bozzolan edited the test plan for this revision. (Show Details)