Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript toUpperCase mess up in chrome for latin character

Here is the code. You can test in Chrome(F12):

"µ".toUpperCase()

This return an invisible character, this should be "µ". It works fine in IE. But why?

In Chrome, returns ""(not empty string, an invisible character)
In IE, returns "µ"
In Firefox, return "M" (not letter M)

like image 795
scott Avatar asked Oct 10 '13 03:10

scott


1 Answers

The correct result is “Μ” U+039C GREEK CAPITAL LETTER MU. Its glyph is identical to the Latin letter “M” in any normal font that contains both, but it’s of course still a different character (in comparisons, transformations, etc.).

According to the ECMAScript standard (clause 15.5.4.18), toUpperCase shall work according to the Unicode Character Database. In it, the uppercase mapping of “µ” U+00B5 MICRO SIGN is U+039C. The reason behind this is that in Unicode, the micro sign is regarded as a separately coded form of the Greek letter mu; formally, a compatibility character that is compatibility equivalent to U+03BC GREEK SMALL LETTER MU. (The two characters “µ” and “μ” may actually have different glyphs in a font, but this does not change their formal properties.)

Thus, Firefox is correct, IE and Chrome are in error in this case. The value that Chrome returns is U+009C, a control character, making no sense, so this is obviously an unintentional bug, a coding error. The IE behavior may be intentionally erroneous, because in practice, the micro sign should never be uppercased. (So the Unicode rule is in this issue absurd, but it’s still the rule that conforming implementations are required to apply.)

The solution is that text containing micro sign should not be uppercased. The micro sign is intended for use in notations of the International system of units, SI, and such a notation in general should never be uppercased. Uppercasing, say, “µs” would not only change the micro prefix to Greek Μ, which looks like a symbol for the mega prefix, but it would also change seconds to siemenses.

like image 186
Jukka K. Korpela Avatar answered Oct 27 '22 19:10

Jukka K. Korpela