Skip to content

Commit 09a575a

Browse files
committed
MFH: fix #41403 (json_decode cannot decode floats if localeconv decimal_point is not '.')
1 parent 69650d0 commit 09a575a

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010
- Fixed altering $this via argument named "this". (Dmitry)
1111
- Fixed PHP CLI to use the php.ini from the binary location. (Hannes)
1212
- Fixed segfault in strripos(). (Tony, Joxean Koret)
13+
- Fixed bug #41403 (json_decode cannot decode floats if localeconv
14+
decimal_point is not '.'). (Tony)
1315
- Fixed bug #41390 (Clarify error message with invalid protocol scheme).
1416
(Scott)
1517
- Fixed bug #41378 (fastcgi protocol lacks support for Reason-Phrase in

ext/json/JSON_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static void json_create_zval(zval **z, smart_str *buf, int type)
288288
}
289289
else if (type == IS_DOUBLE)
290290
{
291-
ZVAL_DOUBLE(*z, atof(buf->c));
291+
ZVAL_DOUBLE(*z, zend_strtod(buf->c, NULL));
292292
}
293293
else if (type == IS_STRING)
294294
{

ext/json/tests/bug41403.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Bug #41403 (json_decode cannot decode floats if localeconv decimal_point is not '.')
3+
--SKIPIF--
4+
<?php
5+
if (setlocale(LC_NUMERIC, "de_DE") === false) {
6+
die("skip no de_DE locale");
7+
}
8+
?>
9+
--INI--
10+
precision=14
11+
--FILE--
12+
<?php
13+
14+
setlocale(LC_NUMERIC, 'de_DE');
15+
var_dump(json_decode('[2.1]'));
16+
var_dump(json_decode('[0.15]'));
17+
var_dump(json_decode('[123.13452345]'));
18+
var_dump(json_decode('[123,13452345]'));
19+
20+
echo "Done\n";
21+
?>
22+
--EXPECTF--
23+
array(1) {
24+
[0]=>
25+
float(2,1)
26+
}
27+
array(1) {
28+
[0]=>
29+
float(0,15)
30+
}
31+
array(1) {
32+
[0]=>
33+
float(123,13452345)
34+
}
35+
array(2) {
36+
[0]=>
37+
int(123)
38+
[1]=>
39+
int(13452345)
40+
}
41+
Done

0 commit comments

Comments
 (0)