? safe-css-class.patch ? sites/default/files Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.845 diff -u -p -r1.845 common.inc --- includes/common.inc 11 Jan 2009 08:39:07 -0000 1.845 +++ includes/common.inc 11 Jan 2009 17:43:20 -0000 @@ -2301,6 +2301,23 @@ function drupal_clear_css_cache() { } /** + * Ensure that a CSS class name only contains legal characters. + * + * We are not using 'a-z' in the regex, as that might leave + * in certain international characters (e.g. German umlauts). + * + * @param $string + * The raw name of the CSS class to prepare. + * @param $token + * The replacement token to use for illegal characters. + * @return + * A safe CSS class string, all lower-case. + */ +function check_class($string, $token = '') { + return preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', $token, strtolower($string)); +} + +/** * Add a JavaScript file, setting or inline code to the page. * * The behavior of this function depends on the parameters it is called with. Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.461 diff -u -p -r1.461 theme.inc --- includes/theme.inc 9 Jan 2009 16:19:55 -0000 1.461 +++ includes/theme.inc 11 Jan 2009 17:43:23 -0000 @@ -1908,10 +1908,8 @@ function template_preprocess_page(&$vari // Add a class that tells us whether the page is viewed by an authenticated user or not. $body_classes[] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in'; // Add arg(0) to make it possible to theme the page depending on the current page - // type (e.g. node, admin, user, etc.). To avoid illegal characters in the class, - // we're removing everything disallowed. We are not using 'a-z' as that might leave - // in certain international characters (e.g. German umlauts). - $body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-' . form_clean_id(drupal_strtolower(arg(0)))); + // type (e.g. node, admin, user, etc.). + $body_classes[] = check_class('page-' . form_clean_id(drupal_strtolower(arg(0)))); // If on an individual node page, add the node type. if (isset($variables['node']) && $variables['node']->type) { $body_classes[] = 'node-type-' . form_clean_id($variables['node']->type); Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.318 diff -u -p -r1.318 block.module --- modules/block/block.module 30 Dec 2008 16:43:15 -0000 1.318 +++ modules/block/block.module 11 Jan 2009 17:43:24 -0000 @@ -217,10 +217,12 @@ function block_block_save($delta = 0, $e /** * Implementation of hook_block_view(). * - * Generates the administrator-defined blocks for display. + * Generates the administrator-defined blocks for display. For easier theming, + * we turn the delta into a string, using only class-safe characters. */ function block_block_view($delta = 0, $edit = array()) { - $block = db_fetch_object(db_query('SELECT body, format FROM {box} WHERE bid = %d', $delta)); + $block = db_fetch_object(db_query('SELECT body, format, info FROM {box} WHERE bid = %d', $delta)); + $data['delta'] = check_class($block->info, '-'); $data['content'] = check_markup($block->body, $block->format, '', FALSE); return $data; } Index: modules/block/block.test =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.test,v retrieving revision 1.9 diff -u -p -r1.9 block.test --- modules/block/block.test 7 Jan 2009 21:41:13 -0000 1.9 +++ modules/block/block.test 11 Jan 2009 17:43:24 -0000 @@ -145,8 +145,12 @@ class BlockTestCase extends DrupalWebTes $this->assertText(t($block['title']), t('Block successfully being displayed on the page.')); // Confirm that the box was found at the proper region. + // For this test to work, we must adjust the delta of custom blocks. See block_block_view(). + if ($block['module'] == 'block') { + $block['delta'] = check_class($block['info'], '-'); + } $xpath = '//div[@id="' . $region['id'] . '"]//div[@id="block-' . $block['module'] . '-' . $block['delta'] . '"]/*'; - $this->assertFieldByXPath($xpath, FALSE, t('Box found in %region_name region.', array('%region_name' => $region['name']))); + $this->assertFieldByXPath($xpath, FALSE, t('Box %delta found in %region_name region.', array('%delta' => $block['delta'], '%region_name' => $region['name']))); } }