Fix Url error for emty baseUrl, less function calls

This commit is contained in:
Thomas Gelf 2014-04-29 12:27:19 +00:00
parent b7f4fa4a29
commit 270181885c

View File

@ -141,24 +141,24 @@ class Url
} }
$urlObject = new Url(); $urlObject = new Url();
$urlObject->setBaseUrl($request->getBaseUrl()); $baseUrl = $request->getBaseUrl();
$urlObject->setBaseUrl($baseUrl);
// Fetch fragment manually and remove it from the url, to 'help' the parse_url() function // Fetch fragment manually and remove it from the url, to 'help' the parse_url() function
// parsing the url properly. Otherwise calling the function with a fragment, but without a // parsing the url properly. Otherwise calling the function with a fragment, but without a
// query will cause unpredictable behaviour. // query will cause unpredictable behaviour.
$url = self::stripUrlFragment($url); $url = self::stripUrlFragment($url);
$urlParts = parse_url($url); $urlParts = parse_url($url);
if (isset($urlParts["path"])) { if (isset($urlParts['path'])) {
if (strpos($urlParts["path"], $request->getBaseUrl()) === 0) { if ($baseUrl !== '' && strpos($urlParts['path'], $baseUrl) === 0) {
$urlObject->setPath(substr($urlParts["path"], strlen($request->getBaseUrl()))); $urlObject->setPath(substr($urlParts['path'], strlen($baseUrl)));
} else { } else {
$urlObject->setPath($urlParts["path"]); $urlObject->setPath($urlParts['path']);
} }
} }
if (isset($urlParts["query"])) { if (isset($urlParts['query'])) {
$urlParams = array(); $urlParams = array();
parse_str($urlParts["query"], $urlParams); parse_str($urlParts['query'], $urlParams);
$params = array_merge($urlParams, $params); $params = array_merge($urlParams, $params);
} }