Commit d4d7a73e authored by stefan.r's avatar stefan.r

Issue #2009584 by hgoto, jtwalters, rteijeiro, ry5n, emattias, Fabianx: Allow...

Issue #2009584 by hgoto, jtwalters, rteijeiro, ry5n, emattias, Fabianx: Allow double underscores to pass through drupal_clean_css_identifier as per new CSS standards
parent 601cfa56
......@@ -8,6 +8,7 @@ Drupal 7.51, xxxx-xx-xx (development version)
- If the page title is "0", it is now displayed.
- Log messages are now XSS filtered on display.
- Draggable tables do now work on touch screen devices.
- Added setting for allowing double underscores in CSS identifiers.
- Numerous performance improvements.
- Numerous small bugfixes.
- Numerous API documentation improvements.
......
......@@ -3900,6 +3900,21 @@ function drupal_delete_file_if_stale($uri) {
* 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', FALSE);
}
// 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);
......
......@@ -947,6 +947,31 @@ class DrupalHTMLIdentifierTestCase extends DrupalUnitTestCase {
// 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 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 by default.');
// Verify that double underscores are preserved in the identifier if the
// variable allow_css_double_underscores is set to TRUE.
$this->setAllowCSSDoubleUnderscores(TRUE);
$this->assertIdentical(drupal_clean_css_identifier($identifier), $identifier, 'Verify double underscores are preserved if the allow_css_double_underscores set to TRUE.');
// To avoid affecting other test cases, set the variable
// allow_css_double_underscores to FALSE which is the default value.
$this->setAllowCSSDoubleUnderscores(FALSE);
}
/**
* Set the variable allow_css_double_underscores and reset the cache.
*
* @param $value bool
* A new value to be set to allow_css_double_underscores.
*/
function setAllowCSSDoubleUnderscores($value) {
$GLOBALS['conf']['allow_css_double_underscores'] = $value;
drupal_static_reset('drupal_clean_css_identifier:allow_css_double_underscores');
}
/**
......
......@@ -616,3 +616,15 @@
* Remove the leading hash sign to enable.
*/
# $conf['theme_debug'] = TRUE;
/**
* CSS identifier double underscores allowance:
*
* To allow CSS identifiers to contain double underscores (.example__selector)
* for Drupal's BEM-style naming standards, uncomment the line below.
* Note that if you change this value in existing sites, existing page styles
* may be broken.
*
* @see drupal_clean_css_identifier()
*/
# $conf['allow_css_double_underscores'] = TRUE;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment