Giter Site home page Giter Site logo

Comments (11)

rurban avatar rurban commented on June 29, 2024

I'm not sure if we should stringify it. It's is left out on purpose: https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript

Other libs convert it to null instead. See e.g. https://code.google.com/p/go/issues/detail?id=3480

from cpanel-json-xs.

Grinnz avatar Grinnz commented on June 29, 2024

There is no way to make roundtrips with inf or nan work, so as long as it produces valid JSON it is acceptable. I mention Mojo::JSON's behavior as a point of reference, converting to null like with blessed references is another option.

from cpanel-json-xs.

rurban avatar rurban commented on June 29, 2024

I'm waiting how upstream JSON decides.

from cpanel-json-xs.

Grinnz avatar Grinnz commented on June 29, 2024

FYI, I have let Marc know about this issue and his response was essentially "it's a bug in your code to produce invalid JSON." So JSON::XS won't be fixing it.

from cpanel-json-xs.

rurban avatar rurban commented on June 29, 2024

Yes, that's the easiest and probable best way to handle it. Let the user check all illegal values, similar to perl, where the user has to check for all potential security problems with no strict 'refs' by himself. javascript shouldn't see inf nor nan.
On the other hand null is the value most others used.
And stringification to "nan", "inf" as in Mojo::JSON, parrot and perl6 keeps the most information.

Let's see what makamaka thinks of it. I have no special opinion.

from cpanel-json-xs.

rurban avatar rurban commented on June 29, 2024

Added now the testcase from makamaka/JSON-PP#10

from cpanel-json-xs.

rurban avatar rurban commented on June 29, 2024

No response.
I'll do it like this:

  • new default: null as in most other JSON libs,
  • or optionally via -DSTRINGIFY_INFNAN "inf" and "nan"

from cpanel-json-xs.

rurban avatar rurban commented on June 29, 2024

Now implemented with cb9007d and fc48ace for 3.0108

from cpanel-json-xs.

Grinnz avatar Grinnz commented on June 29, 2024

Win32 test reports from CPAN testers are getting odd results from inf/nan encoding: http://www.cpantesters.org/cpan/report/ebf54671-6c00-1014-9247-51fd2a825c07

#   Failed test at t/117_numbers.t line 6.
#          got: '[1.#INF]'
#     expected: '[null]'

#   Failed test at t/117_numbers.t line 7.
#          got: '[-1.#IND]'
#     expected: '[null]'

And this one report ended up with [-nan] somehow...
http://www.cpantesters.org/cpan/report/470cdb04-820f-11e4-8cdc-aa95bf9d5952

I think we need two more test cases for -inf and -nan, I just tested these and they are also outputting barewords:

is encode_json([-9**9**9]), '[null]'; # [-inf]
is encode_json([sin(9**9**9)]), '[null]'; # [-nan]
is encode_json([9**9**9/9**9**9]), '[null]'; # also [-nan]

from cpanel-json-xs.

rurban avatar rurban commented on June 29, 2024

yeah. I haven't checked windows and the minus. Ok, I'll add these also.

from cpanel-json-xs.

rurban avatar rurban commented on June 29, 2024

Fixed with 3.0111

from cpanel-json-xs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.