Permalink
Browse files

Fixing issue in Dispatcher::cached() where plugins ending in asset ex…

…tensions would be incorrectly handled.

Test added
Fixes #237
  • Loading branch information...
markstory committed Nov 3, 2009
1 parent 74edb05 commit 8c46cc49fbc234f1d760b5757aa322201e0a1161
View
@@ -598,15 +598,19 @@ function cached($url) {
$this->_stop();
}
$isAsset = false;
- $assets = array('js' => 'text/javascript', 'css' => 'text/css', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'png' => 'image/png');
+ $assets = array(
+ 'js' => 'text/javascript', 'css' => 'text/css',
+ 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'png' => 'image/png'
+ );
$ext = array_pop(explode('.', $url));
foreach ($assets as $type => $contentType) {
if ($type === $ext) {
- if ($type === 'css' || $type === 'js') {
- $pos = strpos($url, $type . '/');
+ $parts = explode('/', $url);
+ if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') {
+ $pos = 0;
} else {
- $pos = strpos($url, 'img/');
+ $pos = strlen($parts[0]);
}
$isAsset = true;
break;
@@ -624,7 +628,7 @@ function cached($url) {
$paths = array();
if ($pos > 0) {
- $plugin = substr($url, 0, $pos - 1);
+ $plugin = substr($url, 0, $pos);
$url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url);
$pluginPaths = Configure::read('pluginPaths');
$count = count($pluginPaths);
@@ -1711,7 +1711,7 @@ function testStaticAssets() {
Configure::write('debug', 0);
ob_start();
- $Dispatcher->dispatch('/img/test.jpg');
+ $Dispatcher->dispatch('img/test.jpg');
$result = ob_get_clean();
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg');
$this->assertEqual($file, $result);
@@ -1756,6 +1756,15 @@ function testStaticAssets() {
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' .DS . 'vendors' . DS . 'img' . DS . 'cake.icon.gif');
$this->assertEqual($file, $result);
+
+ Configure::write('debug', 2);
+ $Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
+ ob_start();
+ $Dispatcher->cached('plugin_js/js/plugin_js.js');
+ $result = ob_get_clean();
+ $expected = "alert('win sauce');";
+ $this->assertEqual($result, $expected);
+
header('Content-type: text/html');//reset the header content-type without page can render as plain text.
}
/**
@@ -0,0 +1 @@
+alert('win sauce');

0 comments on commit 8c46cc4

Please sign in to comment.