Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #17191: improved consistency and readability of UrlManager::creat… #20089

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: Fix `UrlManager::createUrl($params)`, `UrlManager::createAbsoluteUrl($params, $scheme)` methods to rely 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
33 changes: 13 additions & 20 deletions framework/web/UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,16 @@
}

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}";
}

Check warning on line 452 in framework/web/UrlManager.php

View check run for this annotation

Codecov / codecov/patch

framework/web/UrlManager.php#L452

Added line #L452 was not covered by tests

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 Expand Up @@ -559,13 +553,12 @@
{
$params = (array) $params;
$url = $this->createUrl($params);
if (strpos($url, '://') === false) {
$hostInfo = $this->getHostInfo();
if (strncmp($url, '//', 2) === 0) {
$url = substr($hostInfo, 0, strpos($hostInfo, '://')) . ':' . $url;
} else {
$url = $hostInfo . $url;
}
$hostInfo = $this->getHostInfo();
if (Url::isRelative($url)) {
$url = $hostInfo . $url;
}

Check warning on line 559 in framework/web/UrlManager.php

View check run for this annotation

Codecov / codecov/patch

framework/web/UrlManager.php#L559

Added line #L559 was not covered by tests
if (strncmp($url, '//', 2) === 0) {
$url = substr($hostInfo, 0, strpos($hostInfo, '://')) . ':' . $url;
}

return Url::ensureScheme($url, $scheme);
Expand Down
Loading