diff options
Diffstat (limited to 'lua_cjson.c')
| -rw-r--r-- | lua_cjson.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index ca5b88d..c14a1c5 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
| @@ -592,12 +592,20 @@ static void json_append_number(lua_State *l, json_config_t *cfg, | |||
| 592 | if (cfg->encode_invalid_numbers == 0) { | 592 | if (cfg->encode_invalid_numbers == 0) { |
| 593 | /* Prevent encoding invalid numbers */ | 593 | /* Prevent encoding invalid numbers */ |
| 594 | if (isinf(num) || isnan(num)) | 594 | if (isinf(num) || isnan(num)) |
| 595 | json_encode_exception(l, cfg, json, lindex, "must not be NaN or Inf"); | 595 | json_encode_exception(l, cfg, json, lindex, |
| 596 | "must not be NaN or Infinity"); | ||
| 596 | } else if (cfg->encode_invalid_numbers == 1) { | 597 | } else if (cfg->encode_invalid_numbers == 1) { |
| 597 | /* Encode invalid numbers, but handle "nan" separately | 598 | /* Encode NaN/Infinity separately to ensure Javascript compatible |
| 598 | * since some platforms may encode as "-nan". */ | 599 | * values are used. */ |
| 599 | if (isnan(num)) { | 600 | if (isnan(num)) { |
| 600 | strbuf_append_mem(json, "nan", 3); | 601 | strbuf_append_mem(json, "NaN", 3); |
| 602 | return; | ||
| 603 | } | ||
| 604 | if (isinf(num)) { | ||
| 605 | if (num < 0) | ||
| 606 | strbuf_append_mem(json, "-Infinity", 9); | ||
| 607 | else | ||
| 608 | strbuf_append_mem(json, "Infinity", 8); | ||
| 601 | return; | 609 | return; |
| 602 | } | 610 | } |
| 603 | } else { | 611 | } else { |
