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:
mark_story 2011-11-24 21:01:53 -05:00
parent 179a5c8559
commit 5180540d1f
2 changed files with 27 additions and 2 deletions

View file

@ -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.
* *

View file

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