@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix PHP 8.1 "preg_match(null)" exception for missing User-Agent HTTP Header

Summary:
Passing `null` to `preg_match()` is deprecated behavior since PHP 8.1.
Some clients do not pass a `User-Agent` HTTP header so `$agent` is null.
Thus only call `preg_match()` when `$agent` is set.

```
ERROR 8192: preg_match(): preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated
#0 preg_match(string, NULL) called at [<phorge>/src/view/page/PhabricatorStandardPageView.php:629]
```

Closes T15829

Test Plan: Access a task page etc in a browser which does not set a `User-Agent` HTTP Header string.

Reviewers: O1 Blessed Committers, mainframe98, valerio.bozzolan

Reviewed By: O1 Blessed Committers, mainframe98, valerio.bozzolan

Subscribers: mainframe98, slip, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15829

Differential Revision: https://we.phorge.it/D25868

+15 -10
+15 -10
src/view/page/PhabricatorStandardPageView.php
··· 626 626 // Try to guess the device resolution based on UA strings to avoid a flash 627 627 // of incorrectly-styled content. 628 628 $device_guess = 'device-desktop'; 629 - if (preg_match('@iPhone|iPod|(Android.*Chrome/[.0-9]* Mobile)@', $agent)) { 630 - $device_guess = 'device-phone device'; 631 - } else if (preg_match('@iPad|(Android.*Chrome/)@', $agent)) { 632 - $device_guess = 'device-tablet device'; 629 + if (phutil_nonempty_string($agent)) { 630 + if (preg_match('@iPhone|iPod|(Android.*Chrome/[.0-9]* Mobile)@', 631 + $agent)) { 632 + $device_guess = 'device-phone device'; 633 + } else if (preg_match('@iPad|(Android.*Chrome/)@', $agent)) { 634 + $device_guess = 'device-tablet device'; 635 + } 633 636 } 634 637 635 638 $classes[] = $device_guess; 636 639 637 - if (preg_match('@Windows@', $agent)) { 638 - $classes[] = 'platform-windows'; 639 - } else if (preg_match('@Macintosh@', $agent)) { 640 - $classes[] = 'platform-mac'; 641 - } else if (preg_match('@X11@', $agent)) { 642 - $classes[] = 'platform-linux'; 640 + if (phutil_nonempty_string($agent)) { 641 + if (preg_match('@Windows@', $agent)) { 642 + $classes[] = 'platform-windows'; 643 + } else if (preg_match('@Macintosh@', $agent)) { 644 + $classes[] = 'platform-mac'; 645 + } else if (preg_match('@X11@', $agent)) { 646 + $classes[] = 'platform-linux'; 647 + } 643 648 } 644 649 645 650 if ($this->getRequest()->getStr('__print__')) {