Fixed double path slash URL issue in some cases

- Occurred on system request path usage (Primarily on guest login
  redirection) when a custom path was not in use.
- Added test to cover.

For #3404
This commit is contained in:
Dan Brown 2022-05-04 20:08:22 +01:00
parent 16222de5fa
commit ebc69a8f2c
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 17 additions and 1 deletions

View File

@ -35,7 +35,8 @@ class Request extends LaravelRequest
$appUrl = config('app.url', null);
if ($appUrl) {
return '/' . rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
$parsedBaseUrl = rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl);
}
return parent::getBaseUrl();

View File

@ -34,4 +34,19 @@ class UrlTest extends TestCase
$this->assertEquals('/cool/docs', $bsRequest->getBaseUrl());
$this->assertEquals('https://donkey.example.com:8091/cool/docs/login', $bsRequest->getUri());
}
public function test_app_url_without_path_does_not_duplicate_path_slash()
{
config()->set('app.url', 'https://donkey.example.com');
// Have to manually get and wrap request in our custom type due to testing mechanics
$this->get('/settings');
$bsRequest = Request::createFrom(request());
$this->assertEquals('https://donkey.example.com', $bsRequest->getSchemeAndHttpHost());
$this->assertEquals('', $bsRequest->getBaseUrl());
$this->assertEquals('/settings', $bsRequest->getPathInfo());
$this->assertEquals('https://donkey.example.com/settings', $bsRequest->getUri());
}
}