Views row class filtering underscore to dash on direct input

Created on 14 December 2011, over 13 years ago
Updated 8 August 2025, 15 days ago

Problem/Motivation

When defining a class name that contains a single underscore, the underscore is changed to a dash in the rendered output.

This might be related to πŸ› Raw value tokens not replaced if used in css class Postponed: needs info where all input is run through a sanitize function in the row class. I would expect it to leave any entered input alone, but sanitize any token input. This is how the rest of Views works, I can enter in list classes and such and they are not run through a sanitize function.

Steps to reproduce

Single underscore replaced with dash

  1. Create a View
  2. Add a class under Advanced > CSS class with a single underscore, for example my_single
  3. Inspect the source, and see that the underscore is transformed to a dash: my-single

Double underscores not transformed

  1. Create a View
  2. Add a class under Advanced > CSS class with a double underscore, for example my__double
  3. Inspect the source, and see the class is output as my__double, the underscores are not transformed

Style options > Row class field
The same happens in the Style options > Row class field. If you enter my_single_row my__double__row the output is my-single-row my__double__row.

Proposed resolution

Do not transform a single underscore in a class name in a View.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡ΊπŸ‡ΈUnited States rory_o

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    This bug seems to still exist in Drupal 11, and since Drupal 7 is EOL, I am updating the version.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Adding suggestions for help text in Issue Summary, in case it's the intended behaviour.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Interestingly, the error message and the regex are in conflict -- the error text states that underscores are not allowed, yet is included in the regex as an accepted character. I also found the reason for the behaviour, and updated the Issue Summary.

Production build 0.71.5 2024