Skip to content

Commit

Permalink
Fixing issue in Dispatcher::cached() where plugins ending in asset ex…
Browse files Browse the repository at this point in the history
…tensions would be incorrectly handled.

Test added
Fixes #237
  • Loading branch information
markstory committed Nov 3, 2009
1 parent 74edb05 commit 8c46cc4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
14 changes: 9 additions & 5 deletions cake/dispatcher.php
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion cake/tests/cases/dispatcher.test.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
}
/**
Expand Down
@@ -0,0 +1 @@
alert('win sauce');

0 comments on commit 8c46cc4

Please sign in to comment.