Bug #78113 [NEW]: Number formatting does not properly handle locales with multibyte decimal_point

From: Date: Wed, 05 Jun 2019 17:38:27 +0000
Subject: Bug #78113 [NEW]: Number formatting does not properly handle locales with multibyte decimal_point
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221141@lists.php.net to get a copy of this message
From: bjorsch at wikimedia dot org Operating system: Debian sid PHP version: 7.3Git-2019-06-05 (Git) Package: *General Issues Bug Type: Bug Bug description:Number formatting does not properly handle locales with multibyte decimal_point Description: ------------ PHP's support for locales in its number formatting assumes that 'decimal_point' will be a single char. This is not always the case, however. On my system, for example, locale "ps_AF" has it as "٫" as represented in UTF-8 encoding.[1] PHP uses only the first byte of that, producing "Ù" in the console output. This seems to affect at least string casts and the printf() family of functions. I note though that number_format() is not affected, it works fine when multibyte values are passed for the separators. I reproduce this in PHP 7.0.31, 7.1.20, 7.2.11, 7.3.4, and current git master (5f3ee3afe7). [1]: Note this is not really a Unicode issue though. If the locale had decimal_point set to the string "dec" for some reason, PHP would similarly use only "d". Test script: --------------- <?php echo PHP_VERSION . "\n"; $n = 123456.789; // If this locale doesn't exist on your system or doesn't have a non-ASCII // 'decimal_point', change it to one that does. var_dump( setlocale( LC_NUMERIC, 'ps_AF' ) ); var_dump( localeconv() ); echo "$n\n"; printf( "%.15g\n", $n ); echo number_format( $n, 3, localeconv()['decimal_point'], localeconv()['thousands_sep'] ) . "\n"; Expected result: ---------------- 8.0.0-dev string(5) "ps_AF" array(18) { ["decimal_point"]=> string(2) "٫" ["thousands_sep"]=> string(2) "٬" ["int_curr_symbol"]=> string(0) "" ["currency_symbol"]=> string(0) "" ["mon_decimal_point"]=> string(0) "" ["mon_thousands_sep"]=> string(0) "" ["positive_sign"]=> string(0) "" ["negative_sign"]=> string(0) "" ["int_frac_digits"]=> int(127) ["frac_digits"]=> int(127) ["p_cs_precedes"]=> int(127) ["p_sep_by_space"]=> int(127) ["n_cs_precedes"]=> int(127) ["n_sep_by_space"]=> int(127) ["p_sign_posn"]=> int(127) ["n_sign_posn"]=> int(127) ["grouping"]=> array(1) { [0]=> int(3) } ["mon_grouping"]=> array(0) { } } 123456٫789 123456٫789 123٬456٫789 Actual result: -------------- 8.0.0-dev string(5) "ps_AF" array(18) { ["decimal_point"]=> string(2) "٫" ["thousands_sep"]=> string(2) "٬" ["int_curr_symbol"]=> string(0) "" ["currency_symbol"]=> string(0) "" ["mon_decimal_point"]=> string(0) "" ["mon_thousands_sep"]=> string(0) "" ["positive_sign"]=> string(0) "" ["negative_sign"]=> string(0) "" ["int_frac_digits"]=> int(127) ["frac_digits"]=> int(127) ["p_cs_precedes"]=> int(127) ["p_sep_by_space"]=> int(127) ["n_cs_precedes"]=> int(127) ["n_sep_by_space"]=> int(127) ["p_sign_posn"]=> int(127) ["n_sign_posn"]=> int(127) ["grouping"]=> array(1) { [0]=> int(3) } ["mon_grouping"]=> array(0) { } } 123456Ù789 123456Ù789 123٬456٫789 -- Edit bug report at https://bugs.php.net/bug.php?id=78113&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=78113&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=78113&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=78113&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=78113&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78113&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78113&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78113&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78113&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78113&r=support Expected behavior: https://bugs.php.net/fix.php?id=78113&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78113&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78113&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78113&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78113&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=78113&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78113&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78113&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78113&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78113&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78113&r=mysqlcfg

« previous php.bugs (#221141) next »