Page MenuHomePhabricator

locale-aware float to string conversion in Html::srcSet
Closed, DuplicatePublic


In servers where the server locale is set to a language that uses the comma as a decimal separator, direct conversion of float values to string result in a number with a comma as the decimal separator instead of a dot, which causes problems when it's being used in machine-readable values or properties, like HTML/CSS/JavaScript.

One of the examples are in the srcset HTML attribute used on images, generated at Html::srcSet. The value is cast to float and then to string, causing locales with comma as decimal separator (like es_ES or fr_FR output 1,5 instead of 1.5. Such conversions should be done with PHP number_format.

I wonder if it would be safe to simply set setlocale(LC_NUMERIC, "C") somewhere on the code. Who knows where else it may be happening.

Reported originally in Support desk - Comma Instead of Period in SRCSET Breaks IMG Tag

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 24 2017, 12:25 PM
Ciencia_Al_Poder added a subscriber: TheDJ.

We could either use number_format, but then we end up with 1.0x instead of 1x, or I guess we can do character replacement...
Neither is particularly ideal really...