Page MenuHomePhorge

Fix PHP 8.1 "preg_match(null)" exception which blocks rendering the "Browse Herald Rules" dialog
ClosedPublic

Authored by aklapper on May 26 2023, 21:34.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 06:32
Unknown Object (File)
Mon, Apr 22, 01:12
Unknown Object (File)
Sun, Apr 21, 21:59
Unknown Object (File)
Sun, Apr 21, 17:14
Unknown Object (File)
Tue, Apr 16, 13:30
Unknown Object (File)
Sun, Apr 7, 10:29
Unknown Object (File)
Sun, Mar 31, 03:10
Unknown Object (File)
Mar 27 2024, 17:01

Details

Summary

preg_match() does not accept passing null as the $subject string parameter in PHP 8.1.

Thus first check that $subject !== null.

EXCEPTION: (RuntimeException) preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(head=master, ref.master=0e32dbc1ac8f), phorge(head=diffusionRepoPage, ref.master=5405134fa5db, ref.diffusionRepoPage=dbe5e3a68c41)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<arcanist>/src/error/PhutilErrorHandler.php:261]
  #1 <#2> preg_match(string, NULL) called at [<phorge>/src/applications/herald/typeahead/HeraldRuleDatasource.php:25]

Closes T15422

Test Plan

Applied this change; afterwards on the "Diffusion 🡒 Push Logs 🡒 Advanced Search" page at /diffusion/pushlog/?repositories=PHID-REPO-someRepositoryString, clicking the search icon for the "Blocked By" field correctly renders.the "Browse Herald Rules" overlay dialog, listing available Herald rules.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Shorten 87 char line to pass linter

Thanks again :) Soft +1

Also here our phutil is maybe overkill since an emtpy string is a don't care. So a strict check anti-null is probably safer:

$raw_query !== null

Hard +1 in that case from me. Thanks again

Edted: also updating a bit the summary.

Use $raw_query !== null as requested

Thanks for your minimal change

(tip: no need to use brackets, but that is up to readability preferences I guess)

sgtm

This revision is now accepted and ready to land.May 31 2023, 07:09
aklapper retitled this revision from Fix PHP 8.1 "strlen(null)" exception which blocks rendering the "Browse Herald Rules" dialog to Fix PHP 8.1 "preg_match(null)" exception which blocks rendering the "Browse Herald Rules" dialog.May 31 2023, 07:37
aklapper edited the summary of this revision. (Show Details)