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)
Sun, Dec 1, 6:28 AM
Unknown Object (File)
Thu, Nov 28, 5:46 PM
Unknown Object (File)
Sun, Nov 24, 8:05 PM
Unknown Object (File)
Fri, Nov 22, 9:23 AM
Unknown Object (File)
Fri, Nov 22, 9:23 AM
Unknown Object (File)
Fri, Nov 22, 8:37 AM
Unknown Object (File)
Oct 24 2024, 7:30 AM
Unknown Object (File)
Oct 9 2024, 1:44 PM
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