Fixed replacement of alias more than once in View::registerJsFile() and View::registerCssFile(), updated tests

This commit is contained in:
SilverFire - Dmitry Naumenko
2016-09-17 10:28:28 +03:00
parent 3ba72da6fa
commit f3dc5c437d
2 changed files with 26 additions and 2 deletions

View File

@ -403,7 +403,7 @@ class View extends \yii\base\View
$webAlias = Yii::getAlias('@web');
if ($webAlias !== '' && strpos($url, $webAlias) === 0) {
$url = str_replace($webAlias, '', $url);
$url = substr($url, strlen($webAlias));
}
$url = strncmp($url, '//', 2) === 0 ? $url : ltrim($url, '/');
@ -482,7 +482,7 @@ class View extends \yii\base\View
$webAlias = Yii::getAlias('@web');
if ($webAlias !== '' && strpos($url, $webAlias) === 0) {
$url = str_replace($webAlias, '', $url);
$url = substr($url, strlen($webAlias));
}
$url = strncmp($url, '//', 2) === 0 ? $url : ltrim($url, '/');

View File

@ -432,6 +432,30 @@ EOF;
'1<link href="/en/blog/backend/assetSources/css/stub.css" rel="stylesheet">234',
'/en/blog/backend'
],
// UTF-8 chars
[
'css', '@web/assetSources/css/stub.css', false,
'1<link href="/рус/сайт/assetSources/css/stub.css" rel="stylesheet">234',
'/рус/сайт'
],
[
'js', '@web/assetSources/js/jquery.js', false,
'123<script src="/汉语/漢語/assetSources/js/jquery.js"></script>4',
'/汉语/漢語'
],
// Custom alias repeats in the asset URL
[
'css', '@web/assetSources/repeat/css/stub.css', false,
'1<link href="/repeat/assetSources/repeat/css/stub.css" rel="stylesheet">234',
'/repeat'
],
[
'js', '@web/assetSources/repeat/js/jquery.js', false,
'123<script src="/repeat/assetSources/repeat/js/jquery.js"></script>4',
'/repeat'
],
];
}