CSS files encoded in UTF-8 with BOM break the design when enabling CSS aggregation

Created on 6 November 2012, about 12 years ago
Updated 26 January 2025, about 23 hours ago

Beta phase evaluation

Problem/Motivation

If a css file is encoded in UTF-8 with BOM (byte order mark) it breaks the design when enabling css aggregation.

In accordance with the CSS3 spec, Drupal should support UTF-8 encoding in style sheets:
http://www.w3.org/TR/2013/WD-css-syntax-3-20130919/#determine-the-fallba...

Starting with Sass 3.4, the BOM is added automatically when non-ascii content is detected, so this problem will become increasingly common (see https://github.com/sass/sass/blob/3.4.0/lib/sass/tree/visitors/to_css.rb... ).

To reproduce, run
php ./vendor/phpunit/phpunit/phpunit --filter=CssOptimizerUnitTest
with 1833356_test.patch.

Proposed resolution

Checks the encoding on input files (per the fallbacks in the CSS3 spec), and converts non-unicode input to UTF8.

Remaining tasks

Reviews needed

User interface changes

N/A

API changes

N/A

Original report by sammuell

If a css file is encoded in UTF-8 with BOM (byte order mark) it breaks the design when enabling css aggregation. The byte order mark will be inserted at the beginning of every aggregated file (showing up as a questionmark in the code), breaking the first css declaration.

span.AveragePoints{font-size:12pt;margin-bottom:20px;}
?div#Timeline{width:100%;height:200px;text-align:center;}

The issue can be fixed by encoding the files in UTF-8 without BOM, e.g. in Notepad++. However this information does currently not seem to be documented. Where is the best place to put this information? drupal_add_css()?

πŸ› Bug report
Status

Fixed

Version

8.0 ⚰️

Component

base system

Created by

πŸ‡¨πŸ‡­Switzerland sammuell

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

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.

Production build 0.71.5 2024