1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Fix PHP 8.1 issue in DifferentialChangeset getOldStatePathVector()

Summary:
The DifferentialChangeset getOldStatePathVector() method assumes oldFile and filename are set.
This worked under PHP <= 8.0, but fails for PHP >= 8.1 with error messsage

```
strlen(): Passing null to parameter #1 ($string) of type string is deprecated
```

Fixes T15517

Test Plan:
Create a diff in which a new file is added.
This file will have oldFile NULL and filename a string.
View the diff https://my.phorge.site/D1234

Reviewers: O1 Blessed Committers, Matthew

Reviewed By: O1 Blessed Committers, Matthew

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

Maniphest Tasks: T15517

Differential Revision: https://we.phorge.it/D25323
This commit is contained in:
Steve Campbell 2023-08-12 08:37:24 +01:00 committed by sten
parent 98dfac53ba
commit e8ea7a4a36
3 changed files with 24 additions and 4 deletions

View file

@ -488,6 +488,7 @@ phutil_register_library_map(array(
'DifferentialChangesetRenderer' => 'applications/differential/render/DifferentialChangesetRenderer.php',
'DifferentialChangesetSearchConduitAPIMethod' => 'applications/differential/conduit/DifferentialChangesetSearchConduitAPIMethod.php',
'DifferentialChangesetSearchEngine' => 'applications/differential/query/DifferentialChangesetSearchEngine.php',
'DifferentialChangesetTestCase' => 'applications/differential/storage/__tests__/DifferentialChangesetTestCase.php',
'DifferentialChangesetTestRenderer' => 'applications/differential/render/DifferentialChangesetTestRenderer.php',
'DifferentialChangesetTwoUpRenderer' => 'applications/differential/render/DifferentialChangesetTwoUpRenderer.php',
'DifferentialChangesetTwoUpTestRenderer' => 'applications/differential/render/DifferentialChangesetTwoUpTestRenderer.php',
@ -6501,6 +6502,7 @@ phutil_register_library_map(array(
'DifferentialChangesetRenderer' => 'Phobject',
'DifferentialChangesetSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'DifferentialChangesetSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DifferentialChangesetTestCase' => 'PhabricatorTestCase',
'DifferentialChangesetTestRenderer' => 'DifferentialChangesetRenderer',
'DifferentialChangesetTwoUpRenderer' => 'DifferentialChangesetHTMLRenderer',
'DifferentialChangesetTwoUpTestRenderer' => 'DifferentialChangesetTestRenderer',

View file

@ -325,14 +325,16 @@ final class DifferentialChangeset
public function getOldStatePathVector() {
$path = $this->getOldFile();
if (!strlen($path)) {
if (!phutil_nonempty_string($path)) {
$path = $this->getFilename();
}
$path = trim($path, '/');
$path = explode('/', $path);
if (!phutil_nonempty_string($path)) {
return null;
}
return $path;
$path = trim($path, '/');
return explode('/', $path);
}
public function getNewStatePathVector() {

View file

@ -0,0 +1,16 @@
<?php
final class DifferentialChangesetTestCase extends PhabricatorTestCase {
public function testPhp81() {
$diff_change_set = new DifferentialChangeset();
try {
$old_state_vector = $diff_change_set->getOldStatePathVector();
$this->assertTrue(true, 'getOldStatePathVector did not throw an error');
} catch (Throwable $ex) {
$this->assertTrue(false,
'getOldStatePathVector threw an exception:'.$ex->getMessage());
}
}
}