Page MenuHomePhabricator

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

Description

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

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...

I also just ran into this. The default debian installation in Germany installs Debian with a localized PHP, so thumbnails seems to be broken for a lot of german users so far.

Please fix this or just use "1.5x" and "2x" as constants if the number formatter is to hard to use... you don't output other factors anyway :).