From 0adef03fdfee29d3bab0cca083af001ed91c18d9 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Mon, 11 Jan 2021 04:04:23 +0000 Subject: [PATCH] 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", 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 --- src/parser/PhutilTypeSpec.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/parser/PhutilTypeSpec.php b/src/parser/PhutilTypeSpec.php index c49fccf4..c7998074 100644 --- a/src/parser/PhutilTypeSpec.php +++ b/src/parser/PhutilTypeSpec.php @@ -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();