Page MenuHomePhorge

Fix PHP 8.1 "trim(null)" exception which blocks rendering Conduit's harbormaster.sendmessage page
ClosedPublic

Authored by aklapper on May 29 2023, 14:54.

Details

Summary

Since PHP 8.1, passing a null string to trim() is deprecated.
Thus first check that $content is not null before trimming it.

Also since trim() returns a string and never null, we can also simplify the non-empty check,
in a more readable and efficient way, avoiding strlen() that was usually used for other "more wild" cases.

EXCEPTION: (RuntimeException) trim(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(head=master, ref.master=18554ea76ceb), phorge(head=master, ref.master=0d81da590923)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<arcanist>/src/error/PhutilErrorHandler.php:261]
  #1 <#2> trim(NULL) called at [<phorge>/src/infrastructure/markup/blockrule/PhutilRemarkupTableBlockRule.php:117]

Closes T15427

Test Plan

Applied this change, afterwards /conduit/method/harbormaster.sendmessage/ correctly rendered in web browser.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

speck requested changes to this revision.Jun 8 2023, 00:38
speck added inline comments.
src/infrastructure/markup/blockrule/PhutilRemarkupTableBlockRule.php
117–118

Please simplify this

This revision now requires changes to proceed.Jun 8 2023, 00:38
src/infrastructure/markup/blockrule/PhutilRemarkupTableBlockRule.php
117–118

Another possibility:

if ($content === null || trim($content) === '') {

Simplify logic; use null check instead

Thanks for the edit :) I would wait for another "OK" also from speck, premising that sgtm

I think !strlen(trim($var)) is more semantically meaningful than comparing to the empty string but this is fine. Locating calls to strlen which do not compare its return value to another value is more indicative of a non-empty check m, and easier to identify later on

This revision is now accepted and ready to land.Jun 10 2023, 14:22