neolithos / neolua

A Lua implementation for the Dynamic Language Runtime (DLR).
https://neolua.codeplex.com/
Apache License 2.0
466 stars 76 forks source link

ToJson creates invalid Json when encoding +/- infinity #135

Closed thoj closed 2 years ago

thoj commented 2 years ago

NeoLua Version: latest

Example to reproduce: Json output if there is a Infinity number:

{
 "test1": 0.0,
 "test2": -Infinity.0
}

Not a huge issue, and easily worked around, but the application consuming this crashed spectacularly. hehe.

https://www.ietf.org/rfc/rfc4627.txt (2.4)

"Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted."

Not sure how to handle this properly. My suggestion would be just to use the string "-/+Infinity" instead.

neolithos commented 2 years ago

Another solution might be, to emit a "nil"?