Zend Framework

Float values containing commas are not encoded correctly

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6.1
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Json
  • Labels:
    None

Description

A float value such as 10.3 that is represented by 10,3 in some locales is not encoded correctly. The resulting JSON string will contain an extra comma.

Activity

Hide
Matthew Weier O'Phinney added a comment -

Please clarify: was this result obtained using Zend_Json::encode(), or Zend_Json_Encoder::encode()? If the former, do you have ex/tjson installed? The reason I ask is that this may be an upstream (PHP) bug.

Show
Matthew Weier O'Phinney added a comment - Please clarify: was this result obtained using Zend_Json::encode(), or Zend_Json_Encoder::encode()? If the former, do you have ex/tjson installed? The reason I ask is that this may be an upstream (PHP) bug.
Hide
Christoph Dorn added a comment -

Json extension is instaled and loaded:

json support enabled
json version 1.2.1

tested on PHP 5.2.5 and 5.2.6 - same output

And test code:

$data = array ();
for($i = 1; $i < 10; $i ++) { $data [] = rand ( 0, 10 ) / rand ( 2, 9 ); }
echo '<pre>'; var_dump ( $data ); echo '</pre>';
echo '<pre>json_encode'; print_r( json_encode( $data ) ); echo '</pre>';
echo '<pre>ZJE::e'; print_r ( Zend_Json_Encoder::encode ( $data ) ); echo '</pre>';
echo '<pre>ZE::e'; print_r ( Zend_Json::encode ( $data ) ); echo '</pre>';

array(9) {
[0]=>
int(2)
[1]=>
float(1,14285714286)
[2]=>
int(3)
[3]=>
float(1,42857142857)
[4]=>
float(1,75)
[5]=>
float(1,33333333333)
[6]=>
int(0)
[7]=>
float(1,28571428571)
[8]=>
float(0,5)
}

json_encode[2,1.14285714286,3,1.42857142857,1.75,1.33333333333,0,1.28571428571,0.5]

ZJE::e[2,1,14285714286,3,1,42857142857,1,75,1,33333333333,0,1,28571428571,0,5]

ZE::e[2,1.14285714286,3,1.42857142857,1.75,1.33333333333,0,1.28571428571,0.5]

Show
Christoph Dorn added a comment - Json extension is instaled and loaded: json support enabled json version 1.2.1 tested on PHP 5.2.5 and 5.2.6 - same output And test code: $data = array (); for($i = 1; $i < 10; $i ++) { $data [] = rand ( 0, 10 ) / rand ( 2, 9 ); } echo '<pre>'; var_dump ( $data ); echo '</pre>'; echo '<pre>json_encode'; print_r( json_encode( $data ) ); echo '</pre>'; echo '<pre>ZJE::e'; print_r ( Zend_Json_Encoder::encode ( $data ) ); echo '</pre>'; echo '<pre>ZE::e'; print_r ( Zend_Json::encode ( $data ) ); echo '</pre>'; array(9) { [0]=> int(2) [1]=> float(1,14285714286) [2]=> int(3) [3]=> float(1,42857142857) [4]=> float(1,75) [5]=> float(1,33333333333) [6]=> int(0) [7]=> float(1,28571428571) [8]=> float(0,5) } json_encode[2,1.14285714286,3,1.42857142857,1.75,1.33333333333,0,1.28571428571,0.5] ZJE::e[2,1,14285714286,3,1,42857142857,1,75,1,33333333333,0,1,28571428571,0,5] ZE::e[2,1.14285714286,3,1.42857142857,1.75,1.33333333333,0,1.28571428571,0.5]
Hide
Matthew Weier O'Phinney added a comment -

I'm a bit loathe to alter Zend_Json_Encoder to have different results than json_encode(). Is there a bug filed on php.net to alter this behavior for ext/json? If so, I think we can make the change and indicate in the manual in what version of PHP it is (will be) fixed.

Show
Matthew Weier O'Phinney added a comment - I'm a bit loathe to alter Zend_Json_Encoder to have different results than json_encode(). Is there a bug filed on php.net to alter this behavior for ext/json? If so, I think we can make the change and indicate in the manual in what version of PHP it is (will be) fixed.
Hide
Christoph Dorn added a comment -

Hmm. Looking at the tests above it looks like json_encode() is working properly and Zend_Json_Encoder is not.

json_encode[2,1.14285714286,3,1.42857142857,1.75,1.33333333333,0,1.28571428571,0.5]

ZJE::e[2,1,14285714286,3,1,42857142857,1,75,1,33333333333,0,1,28571428571,0,5]

Show
Christoph Dorn added a comment - Hmm. Looking at the tests above it looks like json_encode() is working properly and Zend_Json_Encoder is not. json_encode[2,1.14285714286,3,1.42857142857,1.75,1.33333333333,0,1.28571428571,0.5] ZJE::e[2,1,14285714286,3,1,42857142857,1,75,1,33333333333,0,1,28571428571,0,5]
Hide
Benjamin Eberlei added a comment -

I reproduced this issue and committed a fix in r14400, scheduled for 1.8 release

Show
Benjamin Eberlei added a comment - I reproduced this issue and committed a fix in r14400, scheduled for 1.8 release

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: