Page MenuHomePhabricator

Fix PhutilTypeSpec's regex handling for PHP 8
ClosedPublic

Authored by jrtc27 on Jan 11 2021, 2:04 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 11, 2:23 AM
Unknown Object (File)
Sun, Mar 10, 9:04 PM
Unknown Object (File)
Feb 13 2024, 4:47 AM
Unknown Object (File)
Feb 4 2024, 12:33 AM
Unknown Object (File)
Jan 31 2024, 11:37 AM
Unknown Object (File)
Dec 26 2023, 8:59 PM
Unknown Object (File)
Dec 25 2023, 3:25 AM
Unknown Object (File)
Dec 24 2023, 3:57 AM
Subscribers

Details

Summary

In previous versions, passing the wrong type to preg_match would give a
warning that could be suppressed by @ and caught by set_error_handler,
but as of PHP 8 this raises a TypeError and so remains uncaught. Thus
check up-front whether the provided value is a string.

This fixes linting arc itself when run with PHP 8, as includes and
excludes use "optional regex | list<regex>", so would previously try to
pass an array to preg_match for the first alternative and die.

Test Plan

Ran arc lint

Diff Detail

Repository
rARC Arcanist
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

preg_match() in all modern versions of PHP seems to be willing to accept an object with __toString() as the first parameter:

https://3v4l.org/KEAdq

...but I think it's correct to interpret the PhutilTypeSpec "regex" value as "a genuine string, exactly", particularly given how aggressively interesting PHP's __toString() is (see D20139) -- although it looks like this was finally fixed in PHP 7.4:

https://3v4l.org/me5Zf

I'm quite certain we never pass string-objects to preg_match(), and am happy to fix it when it breaks if I'm wrong.

This revision is now accepted and ready to land.Jan 11 2021, 3:38 AM