WebKit CSS content Unicode bug?
Asked Answered
A

1

5

On one page, I'm using a custom web font (using @font-face) for icons. Each character in the set has an appropriate Unicode value.

In WebKit-based browsers (Chrome, Safari, Android), one of the glyphs isn't shown. Instead, the default glyph or a diamond with a question-mark inside of it is shown.

In Firefox, Opera, and even Internet Explorer, the characters are all rendered properly.

Except for Safari (Windows), this problem only occurs when I insert the Unicode characters via the content CSS property. If I insert the character directly into the HTML using a character reference, it renders properly.

For example, when the Unicode characters are inserted as CSS content ...

/* CSS: */
span.css_font_icon:before {
    display: inline;
    font-family: "Ghodmode Icons", "Webdings", sans-serif;
    content: '\002302 \01F4A1 \00270D \002139';
}

<!-- HTML -->
<span class="css_font_icon"></span>

... they all show in Firefox, Opera, and Internet Explorer, but the second one (\01F4A1) doesn't show in any Webkit browsers on Linux, Windows, or Android. Instead, it shows the default glyph (on Android browsers) or a diamond with a question-mark inside of it (Chrome (Windows), Safari (Windows)).

Inserting the characters using HTML unicode character references ...

/* CSS: */
span.html_font_icon {
    font-family: "Ghodmode Icons", "Webdings", sans-serif;
}

<!-- HTML: -->
<span class="html_font_icon">&#x2302;&#x1F4A1;&#x270D;&#x2139;</span>

... works fine in Firefox, Opera, and Internet Explorer. Chrome (Windows), and Android Webkit browsers also show the symbol from the HTML character reference, but Safari (Windows) shows the default glyph.

I've condensed the original code into a small page that reproduces the problem: http://www.ghodmode.com/testing/unicode-insertion/

Have I stumbled into an unusual WebKit bug, or am I doing something wrong?

I don't have a current iOS device to test this on, so comments describing the behavior on iPhone / iPad are also welcome.

Anabolism answered 11/2, 2012 at 15:47 Comment(0)
D
5

This is a bug in WebKit that only got fixed recently (in April 2012).

To paraphrase my write-up on escape sequences for CSS identifiers:

In theory (as per the spec), any character can be escaped based on its Unicode code point (e.g. for 𝌆, the U+1D306 “tetragram for centre” symbol: \1d306 or \01d306), but older WebKit browsers don’t support this syntax for characters outside the BMP.

Because of browser bugs, there is another (non-standard) way to escape these characters, namely by breaking them up in UTF-16 code units (e.g. \d834\df06), but this syntax (rightfully) isn’t supported in Gecko ++and Opera 12++.

Since there is currently no way to escape non-BMP symbols in a cross-browser fashion, it’s best to just use these characters unescaped.

In your case, the U+1F4A1 character is a supplementary (non-BMP) symbol. All other symbols are BMP characters, so those aren’t affected by the bug.

I’ve also made a tool to help you with CSS escapes, and it warns you if you enter a non-BMP character:

Dendro answered 17/5, 2012 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.