diff --git a/pkgs/racket-pkgs/racket-test/tests/json/json.rkt b/pkgs/racket-pkgs/racket-test/tests/json/json.rkt index f38ec511ae..28fc492673 100644 --- a/pkgs/racket-pkgs/racket-test/tests/json/json.rkt +++ b/pkgs/racket-pkgs/racket-test/tests/json/json.rkt @@ -35,6 +35,9 @@ (not (jsexpr? '#hasheq([1 . 1]))) (not (jsexpr? '#hasheq(["x" . 1]))) (not (jsexpr? '#hasheq(['() . 1]))) + (not (jsexpr? (/ 1.0 0.0))) + (not (jsexpr? (/ -1.0 0.0))) + (not (jsexpr? (/ 0.0 0.0))) ) ;; other `null' values (parameterize ([json-null #\null]) diff --git a/racket/collects/json/main.rkt b/racket/collects/json/main.rkt index b1b21edfe6..7c3544faa1 100644 --- a/racket/collects/json/main.rkt +++ b/racket/collects/json/main.rkt @@ -18,7 +18,7 @@ (define (jsexpr? x #:null [jsnull (json-null)]) (let loop ([x x]) (or (exact-integer? x) - (inexact-real? x) + (real-real? x) (boolean? x) (string? x) (eq? x jsnull) @@ -26,6 +26,9 @@ (and (hash? x) (for/and ([(k v) (in-hash x)]) (and (symbol? k) (loop v))))))) +(define (real-real? x) ; not nan or inf + (and (inexact-real? x) (not (member x '(+nan.0 +inf.0 -inf.0))))) + ;; ---------------------------------------------------------------------------- ;; Generation: Racket -> JSON @@ -64,7 +67,7 @@ (write-string (regexp-replace* rx-to-encode str escape) o) (write-bytes #"\"" o)) (let loop ([x x]) - (cond [(or (exact-integer? x) (inexact-real? x)) (write x o)] + (cond [(or (exact-integer? x) (real-real? x)) (write x o)] [(eq? x #f) (write-bytes #"false" o)] [(eq? x #t) (write-bytes #"true" o)] [(eq? x jsnull) (write-bytes #"null" o)]