Permalink
Browse files

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
  • Loading branch information...
markstory committed Nov 25, 2011
1 parent 7e91d13 commit ff993f893d832220fd0da7fdf689234fe2716bdc
Showing with 27 additions and 2 deletions.
  1. +2 −2 cake/libs/view/helpers/html.php
  2. +25 −0 cake/tests/cases/libs/view/helpers/html.test.php
@@ -346,7 +346,7 @@ function css($path, $rel = null, $options = array()) {
return;
}
if (strpos($path, '://') !== false) {
if (strpos($path, '//') !== false) {
$url = $path;
} else {
if ($path[0] !== '/') {
@@ -427,7 +427,7 @@ function script($url, $options = array()) {
}
$this->__includedScripts[$url] = true;
if (strpos($url, '://') === false) {
if (strpos($url, '//') === false) {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
@@ -464,6 +464,10 @@ function testCssLink() {
$expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
$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);
$result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic'))));
@@ -632,6 +636,27 @@ function testScript() {
$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.
*

0 comments on commit ff993f8

Please sign in to comment.