Skip to content

Commit

Permalink
Fix protocol relative urls for CSS and JS files.
Browse files Browse the repository at this point in the history
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 179a5c8 commit 5180540
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -490,6 +490,10 @@ public 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'))));
Expand Down Expand Up @@ -651,6 +655,27 @@ public 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.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -399,7 +399,7 @@ public function css($path, $rel = null, $options = array()) {
return;
}

if (strpos($path, '://') !== false) {
if (strpos($path, '//') !== false) {
$url = $path;
} else {
if ($path[0] !== '/') {
Expand Down Expand Up @@ -491,7 +491,7 @@ public function script($url, $options = array()) {
}
$this->_includedScripts[$url] = true;

if (strpos($url, '://') === false) {
if (strpos($url, '//') === false) {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
Expand Down

0 comments on commit 5180540

Please sign in to comment.