diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index dd7222f13552..c98814bf43a1 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -67,8 +67,8 @@ class UpdateCompanyRequest extends Request { $input = $this->all(); - // if(array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) - // $input['portal_domain'] = str_replace("http:", "https:", $input['portal_domain']); + if(array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) + $input['portal_domain'] = $this->addScheme($input['portal_domain']); if (array_key_exists('settings', $input)) { $input['settings'] = $this->filterSaveableSettings($input['settings']); @@ -105,4 +105,15 @@ class UpdateCompanyRequest extends Request return $settings; } + + private function addScheme($url, $scheme = 'https://') + { + + $url = str_replace("http://", "", $url); + + $url = parse_url($url, PHP_URL_SCHEME) === null ? $scheme . $url : $url; + + return rtrim($url, '/'); + + } } diff --git a/tests/Unit/UrlTest.php b/tests/Unit/UrlTest.php new file mode 100644 index 000000000000..e3a4f64050b2 --- /dev/null +++ b/tests/Unit/UrlTest.php @@ -0,0 +1,59 @@ +assertEquals("https://google.com", $this->addScheme($url)); + } + + public function testNoSchemeAndTrailingSlash() + { + $url = 'google.com/'; + + $this->assertEquals("https://google.com", $this->addScheme($url)); + } + + + public function testNoSchemeAndTrailingSlashAndHttp() + { + $url = 'http://google.com/'; + + $this->assertEquals("https://google.com", $this->addScheme($url)); + } + + private function addScheme($url, $scheme = 'https://') + { + + $url = str_replace("http://", "", $url); + + $url = parse_url($url, PHP_URL_SCHEME) === null ? $scheme . $url : $url; + + return rtrim($url, '/'); + + } + +} \ No newline at end of file