From 1802ebd2ccc1d8beb1594d3becb57b69f9c1a1aa Mon Sep 17 00:00:00 2001 From: sten Date: Sat, 29 Jul 2023 12:51:00 +0100 Subject: [PATCH] Fix PHP 8.1 Diffusion history errors Summary: Fix multiple PHP 8.1 errors when viewing Diffusion history. Fixes T15573 Test Plan: View a diffusion history page. Eg https://my.php81.phorge.site/source/myrepo/history/master/ Reviewers: O1 Blessed Committers, speck Reviewed By: O1 Blessed Committers, speck Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15573 Differential Revision: https://we.phorge.it/D25366 --- .../diffusion/controller/DiffusionHistoryController.php | 9 ++++----- .../diffusion/query/pathid/DiffusionPathIDQuery.php | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionHistoryController.php b/src/applications/diffusion/controller/DiffusionHistoryController.php index fb35d9b6ad..eeb8f13118 100644 --- a/src/applications/diffusion/controller/DiffusionHistoryController.php +++ b/src/applications/diffusion/controller/DiffusionHistoryController.php @@ -50,7 +50,7 @@ final class DiffusionHistoryController extends DiffusionController { // ancestors appropriately, but this would currrently be prohibitively // expensive in the general case. - $show_graph = !strlen($drequest->getPath()); + $show_graph = !phutil_nonempty_string($drequest->getPath()); if ($show_graph) { $history_list ->setParents($history_results['parents']) @@ -98,11 +98,10 @@ final class DiffusionHistoryController extends DiffusionController { $viewer = $this->getViewer(); $repository = $drequest->getRepository(); - $no_path = !strlen($drequest->getPath()); - if ($no_path) { - $header_text = pht('History'); - } else { + if (phutil_nonempty_string($drequest->getPath())) { $header_text = $this->renderPathLinks($drequest, $mode = 'history'); + } else { + $header_text = pht('History'); } $header = id(new PHUIHeaderView()) diff --git a/src/applications/diffusion/query/pathid/DiffusionPathIDQuery.php b/src/applications/diffusion/query/pathid/DiffusionPathIDQuery.php index 7c9e721431..d994410034 100644 --- a/src/applications/diffusion/query/pathid/DiffusionPathIDQuery.php +++ b/src/applications/diffusion/query/pathid/DiffusionPathIDQuery.php @@ -48,6 +48,9 @@ final class DiffusionPathIDQuery extends Phobject { */ public static function normalizePath($path) { + // Ensure we have a string, not a null. + $path = coalesce($path, ''); + // Normalize to single slashes, e.g. "///" => "/". $path = preg_replace('@[/]{2,}@', '/', $path);