Comments (11)
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.
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.
I'm waiting how upstream JSON decides.
from cpanel-json-xs.
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.
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.
Added now the testcase from makamaka/JSON-PP#10
from cpanel-json-xs.
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.
Now implemented with cb9007d and fc48ace for 3.0108
from cpanel-json-xs.
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.
yeah. I haven't checked windows and the minus. Ok, I'll add these also.
from cpanel-json-xs.
Fixed with 3.0111
from cpanel-json-xs.
Related Issues (20)
- values with IOK and pNOK (but not NOK) encoded as floating point, losing precision HOT 1
- Tests started failing again with recent perls and JSON 4.09 and JSON::PP 4.11
- "Subroutine JSON::PP::Boolean::(++ redefined" with newer perls HOT 2
- Remaining warnings with newer perls and JSON::PP HOT 3
- RFE: utf8(0) variant appropriate for byte strings HOT 26
- Check DOS attack via overlarge bignums
- memory leak when allow_nonref is off HOT 1
- Boolean eq overload breaks behaviour of JSON / JSON::XS modules HOT 1
- Bug: Wrong error messages/sometimes crashes or endless loops with invalid JSON in relaxed mode HOT 2
- Bug: allow_barekey decodes UTF-8 differently with and without quotes HOT 1
- Stringified objects are utf-8 encoded HOT 5
- Build is failing with C error: βforβ loop initial declarations are only allowed in C99 mode HOT 3
- Use faster SIMD utf8 validation
- builtin::true and builtin::false HOT 9
- Strange behvaiour with encode_json. HOT 1
- allow_singlequote should also allow \' HOT 2
- Inconsistent encoding of the empty string HOT 4
- unblessed_bool doesn't DWIM (or match the docs). HOT 3
- test failure with perl-5.38.0-RC0 (t/20_unknown.t) HOT 2
- JS-style comments HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpanel-json-xs.