@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 "strlen(null)" exceptions blocking account registration with custom OAuth provider after redirect

Summary:
`strlen()` was used in Phabricator to check if a generic value is a non-empty string.
This behavior is deprecated since PHP 8.1. Phorge adopts `phutil_nonempty_string()` as a replacement.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If phutil_nonempty_string() throws an exception in your
instance, report it to Phorge to evaluate and fix that specific corner case.

```
EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(), ava(), phorge(), wmf-ext-misc()
#0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/applications/auth/provider/PhabricatorOAuth1AuthProvider.php:70]
```

```
EXCEPTION: (RuntimeException) strlen(): Passing null to parameter #1 ($string) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(), ava(), phorge(), wmf-ext-misc()
#0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/applications/auth/view/PhabricatorAuthAccountView.php:32]
```

Closes T15590

Test Plan:
* As an admin, set up custom "MediaWiki" OAuth provider from from https://gitlab.wikimedia.org/-/ide/project/repos/phabricator/extensions/edit/wmf/stable/-/src/oauth/
* As an admin, apply D25373
* As a user, go to `/auth/login/mediawiki:whatever/`
* Select login button
* Allow authentication on third-party site
* Get redirected to Phorge instance
Phorge user account registration page "Create a New Account" at `/auth/register/abcdefghijklmnopqrstuvwxyz0123456/` now renders as expected, instead of displaying errors only.

Reviewers: O1 Blessed Committers, Matthew

Reviewed By: O1 Blessed Committers, Matthew

Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15590

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

+6 -5
+1 -1
src/applications/auth/provider/PhabricatorOAuth1AuthProvider.php
··· 67 67 } 68 68 69 69 $denied = $request->getStr('denied'); 70 - if (strlen($denied)) { 70 + if ($denied) { 71 71 // Twitter indicates that the user cancelled the login attempt by 72 72 // returning "denied" as a parameter. 73 73 throw new PhutilAuthUserAbortedException();
+5 -4
src/applications/auth/view/PhabricatorAuthAccountView.php
··· 29 29 $realname = $account->getRealName(); 30 30 31 31 $use_name = null; 32 - if (strlen($dispname)) { 32 + if (phutil_nonempty_string($dispname)) { 33 33 $use_name = $dispname; 34 - } else if (strlen($username) && strlen($realname)) { 34 + } else if (phutil_nonempty_string($username) && 35 + phutil_nonempty_string($realname)) { 35 36 $use_name = $username.' ('.$realname.')'; 36 - } else if (strlen($username)) { 37 + } else if (phutil_nonempty_string($username)) { 37 38 $use_name = $username; 38 - } else if (strlen($realname)) { 39 + } else if (phutil_nonempty_string($realname)) { 39 40 $use_name = $realname; 40 41 } 41 42