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

Fix PHP 8.1 PhabricatorEditorURIEngine::newForViewer() trim(NULL) error

Summary:
Under PHP 8.1, PhabricatorEditorURIEngine::newForViewer() is throwing a trim(NULL) error when trying to view a diff.
This is because it tries to apply string operations to a user setting which will be null by default.

Fixes T15518

Test Plan:
Unit test added -
  arc unit

Or just view a diff. Eg:
	https://my.phorge.site/D1234

Reviewers: O1 Blessed Committers, valerio.bozzolan, avivey

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

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

Maniphest Tasks: T15518

Differential Revision: https://we.phorge.it/D25324
This commit is contained in:
Steve Campbell 2023-07-03 17:39:52 +01:00
parent 682fe971a4
commit 65e57fe23d
2 changed files with 18 additions and 1 deletions

View file

@ -16,7 +16,7 @@ final class PhabricatorEditorURIEngine
$pattern = $viewer->getUserSetting(PhabricatorEditorSetting::SETTINGKEY);
if (!strlen(trim($pattern))) {
if ($pattern === null || trim($pattern) === '') {
return null;
}

View file

@ -3,6 +3,12 @@
final class PhabricatorEditorURIEngineTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testPatternParsing() {
$map = array(
'' => array(),
@ -129,4 +135,15 @@ final class PhabricatorEditorURIEngineTestCase
}
}
public function testNewForViewer() {
$phabricator_user = $this->generateNewTestUser();
try {
$engine = PhabricatorEditorURIEngine::newForViewer($phabricator_user);
$this->assertTrue(true, 'newForViewer did not throw an error');
} catch (Throwable $ex) {
$this->assertTrue(false,
'newForViewer threw an exception:'.$ex->getMessage());
}
}
}