Skip to content

Commit

Permalink
Fixing asset filtering for assets in themes and plugins. These assets…
Browse files Browse the repository at this point in the history
… should now correctly enter the configured asset filters. Fixes #650.  Fixes #160
  • Loading branch information
markstory committed May 2, 2010
1 parent 257665e commit 4a0ead8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
10 changes: 8 additions & 2 deletions cake/dispatcher.php
Expand Up @@ -556,8 +556,14 @@ function asset($url) {
return false;
}
$filters = Configure::read('Asset.filter');
$isCss = strpos($url, 'ccss/') === 0;
$isJs = strpos($url, 'cjs/') === 0;
$isCss = (
strpos($url, 'ccss/') === 0 ||
preg_match('#^(theme/([^/]+)/ccss/)|(([^/]+)(?<!css)/ccss)/#i', $url)
);
$isJs = (
strpos($url, 'cjs/') === 0 ||
preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i', $url)
);

if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) {
header('HTTP/1.1 404 Not Found');
Expand Down
38 changes: 37 additions & 1 deletion cake/tests/cases/dispatcher.test.php
Expand Up @@ -72,6 +72,7 @@ function cakeError($filename, $params) {
* @access protected
*/
function _stop() {
$this->stopped = true;
return true;
}
}
Expand Down Expand Up @@ -1965,13 +1966,48 @@ function testMissingAssetProcessor404() {
));
$this->assertNoErrors();

$Dispatcher->params = $Dispatcher->parseParams('ccss/cake.generic.css');
ob_start();
$Dispatcher->asset('ccss/cake.generic.css');
$result = ob_get_clean();
$this->assertTrue($Dispatcher->stopped);

header('HTTP/1.1 200 Ok');
}

/**
* test that asset filters work for theme and plugin assets
*
* @return void
*/
function testAssetFilterForThemeAndPlugins() {
$Dispatcher =& new TestDispatcher();
Configure::write('Asset.filter', array(
'js' => '',
'css' => ''
));
$Dispatcher->asset('theme/test_theme/ccss/cake.generic.css');
$this->assertTrue($Dispatcher->stopped);

$Dispatcher->stopped = false;
$Dispatcher->asset('theme/test_theme/cjs/debug_kit.js');
$this->assertTrue($Dispatcher->stopped);

$Dispatcher->stopped = false;
$Dispatcher->asset('test_plugin/ccss/cake.generic.css');
$this->assertTrue($Dispatcher->stopped);

$Dispatcher->stopped = false;
$Dispatcher->asset('test_plugin/cjs/debug_kit.js');
$this->assertTrue($Dispatcher->stopped);

$Dispatcher->stopped = false;
$Dispatcher->asset('css/ccss/debug_kit.css');
$this->assertFalse($Dispatcher->stopped);

$Dispatcher->stopped = false;
$Dispatcher->asset('js/cjs/debug_kit.js');
$this->assertFalse($Dispatcher->stopped);
}
/**
* testFullPageCachingDispatch method
*
Expand Down

0 comments on commit 4a0ead8

Please sign in to comment.