Skip to content

Fixed bug #50224 where float without decimals were converted to integer when encode JSON #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

jrbasso
Copy link
Contributor

@jrbasso jrbasso commented Mar 29, 2014

No description provided.

@jrbasso jrbasso changed the title Fixed bug #50224 where float without decimals were converted to integer Fixed bug #50224 where float without decimals were converted to integer when JSON encode Mar 30, 2014
@jrbasso jrbasso changed the title Fixed bug #50224 where float without decimals were converted to integer when JSON encode Fixed bug #50224 where float without decimals were converted to integer when encode JSON Mar 30, 2014
@@ -406,6 +406,12 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
if (!zend_isinf(d) && !zend_isnan(d)) {
char *tmp;
int l = spprintf(&tmp, 0, "%.*k", (int) EG(precision), d);
if (strstr(tmp, ".") == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why strstr and not strchr? strchr should be faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Replaced.

@smalyshev
Copy link
Contributor

This patch breaks these tests: bug40503.phpt, json_encode_basic.phpt, pass001.1.phpt. The last one worries me the most - I'm not sure putting .0 there is really that good an idea... But in any case tests should pass. I'd recommend to do pull against master so that unit tests could run, when needed, it can be retargeted to suitable branch.

@jrbasso
Copy link
Contributor Author

jrbasso commented Apr 14, 2014

Technically the tests were hiding this bug before because the encoding/decoding wasn't giving a symmetric value (ie, $val === json_decode(json_encode($val)) was false for float with no decimal points (the bug which this PR solves). This is the reason of my changes on the existent tests.

Are you suggesting to retarget this PR to master because the backward compatibility or just to have a testing tool checking it?

@smalyshev
Copy link
Contributor

@jrbasso all pulls should be targeted to master, unless they fix something unique to particular version. The dev merging them will then apply them to appropriate version.

@jrbasso
Copy link
Contributor Author

jrbasso commented Apr 14, 2014

Got it. I will open a new PR targeting master. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants