summaryrefslogtreecommitdiff
path: root/ext/json/json_encoder.c
diff options
context:
space:
mode:
authorJakub Zelenka <bukka@php.net>2015-02-22 20:54:05 +0000
committerJakub Zelenka <bukka@php.net>2015-02-22 20:54:05 +0000
commitad2b751985a9f812c1a1e21455b33d2af58d9cd0 (patch)
tree3a06ceb03bdc63b49a37dc72daa020132cb90ae4 /ext/json/json_encoder.c
parent485345a7f19f87dc8e932f2666a999850c9c7243 (diff)
parent97d809a8a57cb7bc5833917d9e4eeddad749b53b (diff)
downloadphp-git-ad2b751985a9f812c1a1e21455b33d2af58d9cd0.tar.gz
Merge branch 'PHP-5.6'
The fix for master is a bit different (it's fixed in encoder)
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r--ext/json/json_encoder.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index c66f3d5d27..34ee9afb89 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -94,23 +94,24 @@ static inline void php_json_pretty_print_indent(smart_str *buf, int options) /*
/* }}} */
+static inline int php_json_is_valid_double(double d) /* {{{ */
+{
+ return !zend_isinf(d) && !zend_isnan(d);
+}
+/* }}} */
+
static inline void php_json_encode_double(smart_str *buf, double d, int options) /* {{{ */
{
- if (!zend_isinf(d) && !zend_isnan(d)) {
- size_t len;
- char num[PHP_JSON_DOUBLE_MAX_LENGTH];
- php_gcvt(d, EG(precision), '.', 'e', &num[0]);
- len = strlen(num);
- if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) {
- num[len++] = '.';
- num[len++] = '0';
- num[len] = '\0';
- }
- smart_str_appendl(buf, num, len);
- } else {
- JSON_G(error_code) = PHP_JSON_ERROR_INF_OR_NAN;
- smart_str_appendc(buf, '0');
+ size_t len;
+ char num[PHP_JSON_DOUBLE_MAX_LENGTH];
+ php_gcvt(d, EG(precision), '.', 'e', &num[0]);
+ len = strlen(num);
+ if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) {
+ num[len++] = '.';
+ num[len++] = '0';
+ num[len] = '\0';
}
+ smart_str_appendl(buf, num, len);
}
/* }}} */
@@ -293,10 +294,11 @@ static void php_json_escape_string(smart_str *buf, char *s, size_t len, int opti
if ((type = is_numeric_string(s, len, &p, &d, 0)) != 0) {
if (type == IS_LONG) {
smart_str_append_long(buf, p);
- } else if (type == IS_DOUBLE) {
+ return;
+ } else if (type == IS_DOUBLE && php_json_is_valid_double(d)) {
php_json_encode_double(buf, d, options);
+ return;
}
- return;
}
}
@@ -506,7 +508,12 @@ again:
break;
case IS_DOUBLE:
- php_json_encode_double(buf, Z_DVAL_P(val), options);
+ if (php_json_is_valid_double(Z_DVAL_P(val))) {
+ php_json_encode_double(buf, Z_DVAL_P(val), options);
+ } else {
+ JSON_G(error_code) = PHP_JSON_ERROR_INF_OR_NAN;
+ smart_str_appendc(buf, '0');
+ }
break;
case IS_STRING: