1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

Fix PhutilTypeSpec's regex handling for PHP 8

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

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T13588

Differential Revision: https://secure.phabricator.com/D21499
This commit is contained in:
Jessica Clarke 2021-01-11 04:04:23 +00:00 committed by jrtc27
parent 446dcf1ccd
commit 0adef03fdf

View file

@ -75,6 +75,10 @@ final class PhutilTypeSpec extends Phobject {
}
break;
case 'regex':
if (!is_string($value)) {
throw new PhutilTypeCheckException($this, $value, $name);
}
$trap = new PhutilErrorTrap();
$ok = @preg_match($value, '');
$err = $trap->getErrorsAsString();