@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 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

+18 -1
+1 -1
src/infrastructure/editor/PhabricatorEditorURIEngine.php
··· 16 16 17 17 $pattern = $viewer->getUserSetting(PhabricatorEditorSetting::SETTINGKEY); 18 18 19 - if (!strlen(trim($pattern))) { 19 + if ($pattern === null || trim($pattern) === '') { 20 20 return null; 21 21 } 22 22
+17
src/infrastructure/editor/__tests__/PhabricatorEditorURIEngineTestCase.php
··· 3 3 final class PhabricatorEditorURIEngineTestCase 4 4 extends PhabricatorTestCase { 5 5 6 + protected function getPhabricatorTestCaseConfiguration() { 7 + return array( 8 + self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true, 9 + ); 10 + } 11 + 6 12 public function testPatternParsing() { 7 13 $map = array( 8 14 '' => array(), ··· 126 132 pht( 127 133 'Allowed editor "xyz://" template: %s.', 128 134 $input)); 135 + } 136 + } 137 + 138 + public function testNewForViewer() { 139 + $phabricator_user = $this->generateNewTestUser(); 140 + try { 141 + $engine = PhabricatorEditorURIEngine::newForViewer($phabricator_user); 142 + $this->assertTrue(true, 'newForViewer did not throw an error'); 143 + } catch (Throwable $ex) { 144 + $this->assertTrue(false, 145 + 'newForViewer threw an exception:'.$ex->getMessage()); 129 146 } 130 147 } 131 148