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 ($urlPath && $urlPath[0] === '/') {
|
||||||
if ($baseUrl) {
|
if ($baseUrl) {
|
||||||
$urlPath = substr($urlPath, 1);
|
$urlPath = substr($urlPath, 1);
|
||||||
} elseif (strpos($urlPath, $request->getBaseUrl()) === 0) {
|
} else {
|
||||||
$baseUrl = $request->getBaseUrl();
|
$requestBaseUrl = $request->getBaseUrl();
|
||||||
$urlPath = substr($urlPath, strlen($baseUrl) + 1);
|
if ($requestBaseUrl && $requestBaseUrl !== '/' && strpos($urlPath, $requestBaseUrl) === 0) {
|
||||||
|
$urlPath = substr($urlPath, strlen($requestBaseUrl) + 1);
|
||||||
|
$baseUrl = $requestBaseUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif (! $baseUrl) {
|
} elseif (! $baseUrl) {
|
||||||
$baseUrl = $request->getBaseUrl();
|
$baseUrl = $request->getBaseUrl();
|
||||||
|
|
|
@ -158,17 +158,14 @@ class UrlTest extends BaseTestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testWhetherGetRelativeUrlReturnsTheEmptyStringForAbsoluteUrls()
|
||||||
* @depends testWhetherFromPathProperlyRecognizesAndDecodesQueryParameters
|
|
||||||
*/
|
|
||||||
public function testWhetherGetRelativeUrlReturnsTheRelativeUrl()
|
|
||||||
{
|
{
|
||||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2');
|
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'my/test/url.html?param=val¶m2=val2',
|
'',
|
||||||
$url->getRelativeUrl(),
|
$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