mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing issue in Dispatcher::cached() where plugins ending in asset extensions would be incorrectly handled.
Test added Fixes #237
This commit is contained in:
parent
74edb052f3
commit
8c46cc49fb
3 changed files with 20 additions and 6 deletions
|
@ -598,15 +598,19 @@ class Dispatcher extends Object {
|
|||
$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 @@ class Dispatcher extends Object {
|
|||
$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 @@ class DispatcherTest extends CakeTestCase {
|
|||
|
||||
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 @@ 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');
|
||||
$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.
|
||||
}
|
||||
/**
|
||||
|
|
1
cake/tests/test_app/plugins/plugin_js/vendors/js/plugin_js.js
vendored
Normal file
1
cake/tests/test_app/plugins/plugin_js/vendors/js/plugin_js.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
alert('win sauce');
|
Loading…
Reference in a new issue