From 328aee033fbdc704620e2facae4aa68b836217bb Mon Sep 17 00:00:00 2001 From: Valerio Bozzolan Date: Tue, 19 Mar 2024 17:34:07 +0100 Subject: [PATCH] isSelfURI: fix anchors and relative URIs (that are "self" indeed) Summary: Example cases that were wrongly considered external URLs: - "#foo" - "/foo" Note that Phorge usually does not change stable things. In fact this thing was not documented even inline, and was not even in the unit tests. So this is a fix, and not a breaking change. Probably no one had ever tried it. Closes T15182 Test Plan: The already existing unit tests still work. The added ones make sense. There are no problems doing other random things. Reviewers: O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: tobiaswiese, Matthew, Cigaryno Maniphest Tasks: T15182 Differential Revision: https://we.phorge.it/D25555 --- src/infrastructure/env/PhabricatorEnv.php | 2 +- src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 617fb57af9..a471874e43 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -433,7 +433,7 @@ final class PhabricatorEnv extends Phobject { $host = $uri->getDomain(); if (!phutil_nonempty_string($host)) { - return false; + return true; } $host = phutil_utf8_strtolower($host); diff --git a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php index f73299aa12..59e925f15c 100644 --- a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php +++ b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php @@ -243,6 +243,12 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase { 'https://old.example.com/path/to/resource.png' => true, 'https://other.example.com/' => false, + + '/' => true, + '/self' => true, + '#self' => true, + '/#self' => true, + '/self/#self' => true, ); foreach ($map as $input => $expect) { -- 2.51.2