1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-09 16:32:39 +01:00

Fix PHP 8.1 "preg_match(null)" exception in XHPASTNode

Summary:
When `$u` is `null`, `null` is passed to `preg_match()` which is deprecated behavior since PHP 8.1.
Thus first check if `$u === null`.

```
ERROR 8192: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at [/var/www/html/phorge/arcanist/src/parser/xhpast/api/XHPASTNode.php:243]
```

Refs T15926

Test Plan: Either read the code, or probably run something like `arc unit` on D25797?

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15926

Differential Revision: https://we.phorge.it/D25801
This commit is contained in:
Andre Klapper 2024-08-23 13:14:23 +02:00
parent c01198d55f
commit a094105908

View file

@ -235,7 +235,7 @@ final class XHPASTNode extends AASTNode {
switch ($c) { switch ($c) {
case 'x': case 'x':
$u = isset($value[$ii + 1]) ? $value[$ii + 1] : null; $u = isset($value[$ii + 1]) ? $value[$ii + 1] : null;
if (!preg_match('/^[a-f0-9]/i', $u)) { if ($u === null || !preg_match('/^[a-f0-9]/i', $u)) {
// PHP treats \x followed by anything which is not a hex digit // PHP treats \x followed by anything which is not a hex digit
// as a literal \x. // as a literal \x.
$out .= '\\\\'.$c; $out .= '\\\\'.$c;