Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(std/json): invalid generation for NaN and Inf #18020

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/pure/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ runnableExamples:
a1, a2, a0, a3, a4: int
doAssert $(%* Foo()) == """{"a1":0,"a2":0,"a0":0,"a3":0,"a4":0}"""

import hashes, tables, strutils, lexbase, streams, macros, parsejson
import hashes, tables, strutils, lexbase, streams, macros, math, parsejson

import options # xxx remove this dependency using same approach as https://github.com/nim-lang/Nim/pull/14563
import std/private/since
Expand Down Expand Up @@ -333,7 +333,10 @@ proc `%`*(n: BiggestInt): JsonNode =

proc `%`*(n: float): JsonNode =
## Generic constructor for JSON data. Creates a new `JFloat JsonNode`.
result = JsonNode(kind: JFloat, fnum: n)
case n.classify
of fcNan, fcInf, fcNegInf: result = newJNull()
of fcZero, fcNegZero: result = newJInt(0)
else: result = JsonNode(kind: JFloat, fnum: n)

proc `%`*(b: bool): JsonNode =
## Generic constructor for JSON data. Creates a new `JBool JsonNode`.
Expand Down