From 75483791f4af2ce19443d7ff0fdaf151e75e9005 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Jan 2011 17:14:22 -0500 Subject: [PATCH] Small refactor for how HTTP_BASE is generated. Removing non-obvious regular expression. Fixes #1436 --- cake/basics.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 53b717d7e..ac3f02ae0 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -464,17 +464,21 @@ if (!function_exists('array_combine')) { break; case 'HTTP_BASE': $host = env('HTTP_HOST'); - $count = substr_count($host, '.'); - if ($count <= 1) { + $parts = explode('.', $host); + $count = count($parts); + + if ($count === 1) { return '.' . $host; } elseif ($count === 2) { + return '.' . $host; + } elseif ($count === 3) { $gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx'); - $domainName = explode('.', $host); - if (in_array($domainName[1], $gTLD)) { - $host = '.' . $host; + if (in_array($parts[1], $gTLD)) { + return '.' . $host; } } - return preg_replace('/^([^.])*/i', null, $host); + array_shift($parts); + return '.' . implode('.', $parts); break; } return null;