[ruby-core:78208] [Ruby trunk Bug#12955][Third Party's Issue] BigDecimal::INFINITY and BigDecimal::NAN to_json and as_json should error out similar to Float::INFINITY and Float::NAN
From:
nobu@...
Date:
2016-11-18 23:53:10 UTC
List:
ruby-core #78208
Issue #12955 has been updated by Nobuyoshi Nakada.
Description updated
Status changed from Open to Third Party's Issue
Please report it to the [upstream](https://github.com/flori/json).
----------------------------------------
Bug #12955: BigDecimal::INFINITY and BigDecimal::NAN to_json and as_json should error out similar to Float::INFINITY and Float::NAN
https://bugs.ruby-lang.org/issues/12955#change-61573
* Author: Prathamesh Sonpatki
* Status: Third Party's Issue
* Priority: Normal
* Assignee:
* ruby -v:
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Currently, `Float::INFINITY` and `Float::NAN` error out when we try to convert them into JSON representation using `as_json` or `to_json` based on the following code from /ruby/ext/json/generator.c
~~~ c
if (!allow_nan) {
if (isinf(value)) {
fbuffer_free(buffer);
rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
} else if (isnan(value)) {
fbuffer_free(buffer);
rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
}
}
~~~
Should same treatment be applied to `BigDecimal::INFINITY` and `BigDecimal::NAN`?
Here is the RFC link which says that
*Numeric values that cannot be represented as sequences of digits such as Infinity and NaN) are not permitted*
- https://www.ietf.org/rfc/rfc4627.txt
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>