From 38175aee1bdd2db55eaca66c705858568dabc1cf Mon Sep 17 00:00:00 2001 From: Mathieu Ducrot Date: Mon, 25 Nov 2024 12:29:45 +0100 Subject: [PATCH] RequestUtils::getContextFromHost add host ending with '.localhost' fallback --- CHANGELOG_request_utils_get_context_handle_localhost.md | 2 ++ src/Utils/RequestUtils.php | 1 + tests/Utils/RequestUtilsTest.php | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG_request_utils_get_context_handle_localhost.md diff --git a/CHANGELOG_request_utils_get_context_handle_localhost.md b/CHANGELOG_request_utils_get_context_handle_localhost.md new file mode 100644 index 0000000..f822efd --- /dev/null +++ b/CHANGELOG_request_utils_get_context_handle_localhost.md @@ -0,0 +1,2 @@ +### Fixed +- `RequestUtils::getContextFromHost` add host ending with '.localhost' fallback diff --git a/src/Utils/RequestUtils.php b/src/Utils/RequestUtils.php index 7426cdc..562a8e2 100644 --- a/src/Utils/RequestUtils.php +++ b/src/Utils/RequestUtils.php @@ -21,6 +21,7 @@ public static function getContextFromHost(string $host, ?string $domain = null): || str_starts_with($host, 'api.') || str_starts_with($host, 'extranet.') || str_starts_with($host, 'sso.') + || str_ends_with($host, '.localhost') || substr_count($host, '.') > 1 ) { $toReturn = substr($host, 0, (int) strpos($host, '.')); diff --git a/tests/Utils/RequestUtilsTest.php b/tests/Utils/RequestUtilsTest.php index 5dbde47..b9bec49 100644 --- a/tests/Utils/RequestUtilsTest.php +++ b/tests/Utils/RequestUtilsTest.php @@ -24,9 +24,9 @@ public function getContextFromHostProvider(): array 'localhost' => ['app', 'localhost'], 'localhost admin' => ['admin', 'admin.localhost'], 'localhost app' => ['app', 'app.localhost'], + 'localhost account' => ['account', 'account.localhost'], 'localhost partenaire' => ['partenaire', 'partenaire.pro.localhost'], - // MDT to demonstrate that additional subdomain is needed like the test above in the case of localhost because there is no .fr extension - 'localhost fallback with app' => ['app', 'partenaire.localhost'], + 'localhost fallback with app if no ending extension and different than localhost' => ['app', 'domain'], 'custom domain' => ['app', 'domain.fr', 'domain.fr'], 'custom domain subdomain admin' => ['admin', 'admin.domain.fr', 'domain.fr'], 'custom domain subdomain app' => ['app', 'app.domain.fr', 'domain.fr'],