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...
1 parent 179a5c8 commit 5180540d1f5eae68f39ff000f743669ce328d56b @markstory markstory committed Nov 25, 2011
Showing with 27 additions and 2 deletions.
  1. +25 −0 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +2 −2 lib/Cake/View/Helper/HtmlHelper.php
@@ -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'))));
@@ -652,6 +656,27 @@ public function testScript() {
}
/**
+ * 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.
*
* @return void
@@ -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] !== '/') {
@@ -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;
}

0 comments on commit 5180540

Please sign in to comment.