diff -u b/includes/common.inc b/includes/common.inc --- b/includes/common.inc +++ b/includes/common.inc @@ -3873,14 +3873,6 @@ * The cleaned identifier. */ function drupal_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')) { - global $conf; - - // Preserve BEM-style double-underscores depending on custom setting. - // Avoids a variable_get function call to improve performance. - if (!empty($conf['preserve_css_double_underscores'])) { - $filter['__'] = '__'; - } - // By default, we filter using Drupal's coding standards. $identifier = strtr($identifier, $filter); @@ -3901,6 +3893,21 @@ * The cleaned identifier. */ function drupal_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')) { + // Use the advanced drupal_static() pattern, since this is called very often. + static $drupal_static_fast; + if (!isset($drupal_static_fast)) { + $drupal_static_fast['allow_css_double_underscores'] = &drupal_static(__FUNCTION__ . ':allow_css_double_underscores'); + } + $allow_css_double_underscores = &$drupal_static_fast['allow_css_double_underscores']; + if (!isset($allow_css_double_underscores)) { + $allow_css_double_underscores = variable_get('allow_css_double_underscores'); + } + + // Preserve BEM-style double-underscores depending on custom setting. + if ($allow_css_double_underscores) { + $filter['__'] = '__'; + } + // By default, we filter using Drupal's coding standards. $identifier = strtr($identifier, $filter); diff -u b/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test --- b/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -948,20 +948,20 @@ // Verify that invalid characters (including non-breaking space) are stripped from the identifier. $this->assertIdentical(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()), 'invalididentifier', 'Strip invalid characters.'); - // Verify that double underscores are replaced in the identifier. + // Verify that double underscores are replaced in the identifier by default. $identifier = 'css__identifier__with__double__underscores'; $expected = 'css--identifier--with--double--underscores'; - $this->assertIdentical(drupal_clean_css_identifier($identifier), $expected, 'Verify double underscores are replaced with double hyphens.'); + $this->assertIdentical(drupal_clean_css_identifier($identifier), $expected, 'Verify double underscores are replaced with double hyphens by default.'); - // Mock a variable_set of preserve_css_double_underscores to TRUE. - $original = $GLOBALS['conf']['preserve_css_double_underscores']; - $GLOBALS['conf']['preserve_css_double_underscores'] = TRUE; + // Mock a variable_set of allow_css_double_underscores to TRUE. + $original = isset($GLOBALS['conf']['allow_css_double_underscores']) ? $GLOBALS['conf']['allow_css_double_underscores'] : NULL; + $GLOBALS['conf']['allow_css_double_underscores'] = TRUE; // Now, verify that double underscores are preserved in the identifier. $this->assertIdentical(drupal_clean_css_identifier($identifier), $identifier, 'Verify double underscores are preserved.'); // Revert the overridden value above. - $GLOBALS['conf']['preserve_css_double_underscores'] = $original; + $GLOBALS['conf']['allow_css_double_underscores'] = $original; } /** diff -u b/sites/default/default.settings.php b/sites/default/default.settings.php --- b/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -612,7 +612,8 @@ - * Preserve CSS double underscores: + * CSS identifier double underscores allowance: * - * To allow CSS identifiers containing double underscores, e.g., in a BEM-style - * selector (.example__selector), uncomment the line below. + * To allow CSS identifiers to contain double underscores (.example__selector) + * for BEM-style naming standards, uncomment the line below. + * + * @see drupal_clean_css_identifier() */ -# $conf['preserve_css_double_underscores'] = TRUE; - +# $conf['allow_css_double_underscores'] = TRUE;