Url: Fix detection of the current base url when stripping it from a given path
This commit is contained in:
parent
5f7f0a9e89
commit
85e7e7920a
|
@ -161,9 +161,12 @@ class Url
|
|||
if ($urlPath && $urlPath[0] === '/') {
|
||||
if ($baseUrl) {
|
||||
$urlPath = substr($urlPath, 1);
|
||||
} elseif (strpos($urlPath, $request->getBaseUrl()) === 0) {
|
||||
$baseUrl = $request->getBaseUrl();
|
||||
$urlPath = substr($urlPath, strlen($baseUrl) + 1);
|
||||
} else {
|
||||
$requestBaseUrl = $request->getBaseUrl();
|
||||
if ($requestBaseUrl && $requestBaseUrl !== '/' && strpos($urlPath, $requestBaseUrl) === 0) {
|
||||
$urlPath = substr($urlPath, strlen($requestBaseUrl) + 1);
|
||||
$baseUrl = $requestBaseUrl;
|
||||
}
|
||||
}
|
||||
} elseif (! $baseUrl) {
|
||||
$baseUrl = $request->getBaseUrl();
|
||||
|
|
|
@ -158,17 +158,14 @@ class UrlTest extends BaseTestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testWhetherFromPathProperlyRecognizesAndDecodesQueryParameters
|
||||
*/
|
||||
public function testWhetherGetRelativeUrlReturnsTheRelativeUrl()
|
||||
public function testWhetherGetRelativeUrlReturnsTheEmptyStringForAbsoluteUrls()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2');
|
||||
|
||||
$this->assertEquals(
|
||||
'my/test/url.html?param=val¶m2=val2',
|
||||
'',
|
||||
$url->getRelativeUrl(),
|
||||
'Url::getRelativeUrl does not return the relative url'
|
||||
'Url::getRelativeUrl does not return the empty string for absolute urls'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue