on master help sign in
Properly encode NaN and Infinity.

This used to be handled by the blaze-textual package, but that made no sense.

commitc5a463fe39b403e99b00c5a732dea4dabb836c90 authorBryan O'Sullivan <bos@mailrank.com> dateSat 6 Aug 2011, 12:46 (15 years ago) parent00a185a
1 file changed+3−1
Data/Aeson/Encode.hs+3−1
Data/Aeson/Encode.hs+3−1
@@ -70,7 +70,9 @@ string s = fromChar '"' `mappend` quote s `mappend` fromChar '"'
7070
7171fromNumber :: Number -> Builder
7272fromNumber (I i) = integral i
73−fromNumber (D d) = double d
73+fromNumber (D d)
74+ | isNaN d || isInfinite d = "null"
75+ | otherwise = double d
7476
7577-- | Efficiently serialize a JSON value as a lazy 'L.ByteString'.
7678encode :: ToJSON a => a -> L.ByteString