From: Antony Dovgal Date: Wed, 16 May 2007 12:53:36 +0000 (+0000) Subject: fix #41403 (json_decode cannot decode floats if localeconv decimal_point is not '.') X-Git-Tag: RELEASE_1_2_0~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b21fe285687b5a940bd08dd8b7f42f1cb9dd0ae5;p=php fix #41403 (json_decode cannot decode floats if localeconv decimal_point is not '.') --- diff --git a/ext/json/JSON_parser.c b/ext/json/JSON_parser.c index fdd861152b..b041a43cc1 100644 --- a/ext/json/JSON_parser.c +++ b/ext/json/JSON_parser.c @@ -288,7 +288,7 @@ static void json_create_zval(zval **z, smart_str *buf, int type TSRMLS_DC) } else if (type == IS_DOUBLE) { - ZVAL_DOUBLE(*z, atof(buf->c)); + ZVAL_DOUBLE(*z, zend_strtod(buf->c, NULL)); } else if (type == IS_STRING) { diff --git a/ext/json/tests/bug41403.phpt b/ext/json/tests/bug41403.phpt new file mode 100644 index 0000000000..369053fe0d --- /dev/null +++ b/ext/json/tests/bug41403.phpt @@ -0,0 +1,62 @@ +--TEST-- +Bug #41403 (json_decode cannot decode floats if localeconv decimal_point is not '.') +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + +--EXPECTF-- +array(1) { + [0]=> + float(2,1) +} +array(1) { + [0]=> + float(0,15) +} +array(1) { + [0]=> + float(123,13452345) +} +array(2) { + [0]=> + int(123) + [1]=> + int(13452345) +} +Done +--UEXPECTF-- +Strict Standards: setlocale(): deprecated in Unicode mode, please use ICU locale functions in %s on line %d +array(1) { + [0]=> + float(2,1) +} +array(1) { + [0]=> + float(0,15) +} +array(1) { + [0]=> + float(123,13452345) +} +array(2) { + [0]=> + int(123) + [1]=> + int(13452345) +} +Done