Skip to content

Commit

Permalink
fix yiisoft#17191: improved consistency and readability of UrlManager…
Browse files Browse the repository at this point in the history
…::createUrl() method
  • Loading branch information
ggh2e3 committed Dec 24, 2023
1 parent 4c959b5 commit cdaf6f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.50 under development
------------------------

- Bug #17191: Fixed `UrlManager::createUrl($params)` method now relies on `BaseUrl::isRelative($url)` method (ggh2e3)
- Bug #17191: Fixed `BaseUrl::isRelative($url)` method in `yii\helpers\BaseUrl` (ggh2e3)
- Bug #18469: Fixed `Link::serialize(array $links)` method in `yii\web\Link` (ggh2e3)
- Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw)
Expand Down
20 changes: 7 additions & 13 deletions framework/web/UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,16 @@ public function createUrl($params)
}

if ($url !== false) {
if (strpos($url, '://') !== false) {
if ($baseUrl !== '' && ($pos = strpos($url, '/', 8)) !== false) {
return substr($url, 0, $pos) . $baseUrl . substr($url, $pos) . $anchor;
}

return $url . $baseUrl . $anchor;
} elseif (strncmp($url, '//', 2) === 0) {
if ($baseUrl !== '' && ($pos = strpos($url, '/', 2)) !== false) {
return substr($url, 0, $pos) . $baseUrl . substr($url, $pos) . $anchor;
}
if (Url::isRelative($url)) {
$url = ltrim($url, '/');
return "$baseUrl/{$url}{$anchor}";
}

return $url . $baseUrl . $anchor;
if ($baseUrl !== '' && ($pos = strpos($url, '/', 8)) !== false) {
return substr($url, 0, $pos) . $baseUrl . substr($url, $pos) . $anchor;
}

$url = ltrim($url, '/');
return "$baseUrl/{$url}{$anchor}";
return $url . $baseUrl . $anchor;
}

if ($this->suffix !== null) {
Expand Down

0 comments on commit cdaf6f5

Please sign in to comment.