Project

General

Profile

Actions

Bug #12955

closed

BigDecimal::INFINITY and BigDecimal::NAN to_json and as_json should error out similar to Float::INFINITY and Float::NAN

Added by cha1tanya (Prathamesh Sonpatki) almost 8 years ago. Updated almost 8 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
[ruby-core:78196]

Description

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

    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

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Description updated (diff)
  • Status changed from Open to Third Party's Issue

Please report it to the upstream.

Actions

Also available in: Atom PDF

Like0
Like0