mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix protocol relative urls for CSS and JS files.
Protocol relative urls are generally not on the same host don't try and run them through the asset filters. Fixes #2285
This commit is contained in:
parent
179a5c8559
commit
5180540d1f
2 changed files with 27 additions and 2 deletions
|
@ -490,6 +490,10 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
$expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
|
$expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Html->css('//example.com/css/cake.generic.css');
|
||||||
|
$expected['link']['href'] = 'preg:/.*example\.com\/css\/cake\.generic\.css/';
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
Configure::write('Asset.filter.css', false);
|
Configure::write('Asset.filter.css', false);
|
||||||
|
|
||||||
$result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
|
$result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
|
||||||
|
@ -651,6 +655,27 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
$this->assertNull($result);
|
$this->assertNull($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that Asset.filter.js works.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testScriptAssetFilter() {
|
||||||
|
Configure::write('Asset.filter.js', 'js.php');
|
||||||
|
|
||||||
|
$result = $this->Html->script('jquery-1.3');
|
||||||
|
$expected = array(
|
||||||
|
'script' => array('type' => 'text/javascript', 'src' => 'cjs/jquery-1.3.js')
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Html->script('//example.com/js/jquery-1.3.js');
|
||||||
|
$expected = array(
|
||||||
|
'script' => array('type' => 'text/javascript', 'src' => '//example.com/js/jquery-1.3.js')
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test a script file in the webroot/theme dir.
|
* test a script file in the webroot/theme dir.
|
||||||
*
|
*
|
||||||
|
|
|
@ -399,7 +399,7 @@ class HtmlHelper extends AppHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($path, '://') !== false) {
|
if (strpos($path, '//') !== false) {
|
||||||
$url = $path;
|
$url = $path;
|
||||||
} else {
|
} else {
|
||||||
if ($path[0] !== '/') {
|
if ($path[0] !== '/') {
|
||||||
|
@ -491,7 +491,7 @@ class HtmlHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
$this->_includedScripts[$url] = true;
|
$this->_includedScripts[$url] = true;
|
||||||
|
|
||||||
if (strpos($url, '://') === false) {
|
if (strpos($url, '//') === false) {
|
||||||
if ($url[0] !== '/') {
|
if ($url[0] !== '/') {
|
||||||
$url = JS_URL . $url;
|
$url = JS_URL . $url;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue