Fixing issue in Dispatcher::cached() where plugins ending in asset extensions would be incorrectly handled.

Test added
Fixes #237
This commit is contained in:
mark_story 2009-11-03 13:14:38 -05:00
parent 74edb052f3
commit 8c46cc49fb
3 changed files with 20 additions and 6 deletions

View file

@ -598,15 +598,19 @@ class Dispatcher extends Object {
$this->_stop(); $this->_stop();
} }
$isAsset = false; $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)); $ext = array_pop(explode('.', $url));
foreach ($assets as $type => $contentType) { foreach ($assets as $type => $contentType) {
if ($type === $ext) { if ($type === $ext) {
if ($type === 'css' || $type === 'js') { $parts = explode('/', $url);
$pos = strpos($url, $type . '/'); if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') {
$pos = 0;
} else { } else {
$pos = strpos($url, 'img/'); $pos = strlen($parts[0]);
} }
$isAsset = true; $isAsset = true;
break; break;
@ -624,7 +628,7 @@ class Dispatcher extends Object {
$paths = array(); $paths = array();
if ($pos > 0) { if ($pos > 0) {
$plugin = substr($url, 0, $pos - 1); $plugin = substr($url, 0, $pos);
$url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url); $url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url);
$pluginPaths = Configure::read('pluginPaths'); $pluginPaths = Configure::read('pluginPaths');
$count = count($pluginPaths); $count = count($pluginPaths);

View file

@ -1711,7 +1711,7 @@ class DispatcherTest extends CakeTestCase {
Configure::write('debug', 0); Configure::write('debug', 0);
ob_start(); ob_start();
$Dispatcher->dispatch('/img/test.jpg'); $Dispatcher->dispatch('img/test.jpg');
$result = ob_get_clean(); $result = ob_get_clean();
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg'); $file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'img' . DS . 'test.jpg');
$this->assertEqual($file, $result); $this->assertEqual($file, $result);
@ -1756,6 +1756,15 @@ class DispatcherTest extends CakeTestCase {
$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'); $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); $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. header('Content-type: text/html');//reset the header content-type without page can render as plain text.
} }
/** /**

View file

@ -0,0 +1 @@
alert('win sauce');