Permalink
Browse files

Updating HtmlHelper::css, JavascriptHelper::link to not replace multi…

…ple occurences of CSS_URL or JS_URL when using Asset.filter settings.

Test cases added.
Thanks to 'robustsolution' for the patch.
Fixes #105
  • Loading branch information...
1 parent 06cf974 commit 508d737b6aecc8a53e078511e42d4b58d8a553c5 @markstory markstory committed Sep 26, 2009
@@ -352,13 +352,16 @@ function css($path, $rel = null, $htmlAttributes = array(), $inline = true) {
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
Configure::read('Asset.timestamp') === 'force'
);
+
$url = $this->webroot($path);
if (strpos($path, '?') === false && $timestampEnabled) {
$url .= '?' . @filemtime(WWW_ROOT . str_replace('/', DS, $path));
}
-
if (Configure::read('Asset.filter.css')) {
- $url = str_replace(CSS_URL, 'ccss/', $url);
+ $pos = strpos($url, CSS_URL);
+ if ($pos !== false) {
+ $url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL));
+ }
}
}
@@ -263,9 +263,12 @@ function link($url, $inline = true) {
} else {
$url = $this->webroot($url);
}
-
+
if (Configure::read('Asset.filter.js')) {
- $url = str_replace(JS_URL, 'cjs/', $url);
+ $pos = strpos($url, JS_URL);
+ if ($pos !== false) {
+ $url = substr($url, 0, $pos) . 'cjs/' . substr($url, $pos + strlen(JS_URL));
+ }
}
}
$out = $this->output(sprintf($this->tags['javascriptlink'], $url));
@@ -370,12 +370,6 @@ function testCssLink() {
$expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
$this->assertTags($result, $expected);
- Configure::write('Asset.filter.css', 'css.php');
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/.*ccss\/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'))));
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/';
$this->assertTags($result[0], $expected);
@@ -385,12 +379,6 @@ function testCssLink() {
Configure::write('Asset.timestamp', true);
- Configure::write('Asset.filter.css', 'css.php');
- $result = $this->Html->css('cake.generic');
- $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css\?[0-9]+/';
- $this->assertTags($result, $expected);
- Configure::write('Asset.filter.css', false);
-
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
$this->assertTags($result, $expected);
@@ -422,6 +410,40 @@ function testCssLink() {
$this->Html->webroot = $webroot;
}
/**
+ * test css() with Asset.Css.filter
+ *
+ * @return void
+ **/
+ function testCssFiltering() {
+ $this->Html->webroot = '/';
+
+ Configure::write('Asset.filter.css', 'css.php');
+ $result = $this->Html->css('cake.generic');
+ $expected = array(
+ 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/\/ccss\/cake\.generic\.css/')
+ );
+ $this->assertTags($result, $expected);
+
+ Configure::write('Asset.timestamp', true);
+ Configure::write('Asset.filter.css', 'css.php');
+
+ $result = $this->Html->css('cake.generic');
+ $expected['link']['href'] = 'preg:/\/ccss\/cake\.generic\.css\?[0-9]+/';
+ $this->assertTags($result, $expected);
+
+ Configure::write('Asset.timestamp', false);
+ $result = $this->Html->css('myfoldercss/cake.generic');
+ $expected['link']['href'] = 'preg:/\/ccss\/myfoldercss\/cake\.generic\.css/';
+ $this->assertTags($result, $expected);
+
+ $this->Html->webroot = '/testing/longer/';
+ $result = $this->Html->css('myfoldercss/cake.generic');
+ $expected['link']['href'] = 'preg:/\/testing\/longer\/ccss\/myfoldercss\/cake\.generic\.css/';
+ $this->assertTags($result, $expected);
+
+ Configure::write('Asset.filter.css', false);
+ }
+/**
* testCharsetTag method
*
* @access public
@@ -250,6 +250,10 @@ function testFilteringAndTimestamping() {
$expected = '<script type="text/javascript" src="cjs/jquery-1.1.2.js"></script>';
$this->assertEqual($result, $expected);
+ $result = $this->Javascript->link('folderjs/jquery-1.1.2');
+ $expected = '<script type="text/javascript" src="cjs/folderjs/jquery-1.1.2.js"></script>';
+ $this->assertEqual($result, $expected);
+
if ($old === null) {
Configure::delete('Asset.filter.js');
}

0 comments on commit 508d737

Please sign in to comment.