on master help sign in
Fix number parsing
commit045e8cc019cf7386ede9e3ad110d3bea748047b5 authorMichael Snoyman <michael@snoyman.com> dateMon 27 Jan 2014, 20:12 (13 years ago) parentd4cafee
2 files changed+15−4
Data/Yaml.hs+13−3 yaml.cabal+2−1
Data/Yaml.hs+13−3
@@ -84,9 +84,13 @@ import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
8484import Data.Text.Encoding.Error (lenientDecode)
8585import qualified Data.HashMap.Strict as M
8686import Data.Typeable
87−import Data.Attoparsec.ByteString (parseOnly)
88−import Data.Aeson.Parser (value)
8987import qualified Data.HashSet as HashSet
88+import Data.Text.Read
89+#if MIN_VERSION_aeson(0, 7, 0)
90+import Data.Scientific (fromFloatDigits)
91+#else
92+import Data.Attoparsec.Number
93+#endif
9094
9195encode :: ToJSON a => a -> ByteString
9296encode obj = unsafePerformIO $
@@ -210,7 +214,13 @@ textToValue _ _ t
210214 | t `elem` ["null", "Null", "NULL", "~", ""] = Null
211215 | any (t `isLike`) ["y", "yes", "on", "true"] = Bool True
212216 | any (t `isLike`) ["n", "no", "off", "false"] = Bool False
213− | Right (Number n) <- parseOnly value (encodeUtf8 t) = Number n
217+#if MIN_VERSION_aeson(0, 7, 0)
218+ | Right (x, "") <- signed decimal t = Number $ fromIntegral (x :: Integer)
219+ | Right (x, "") <- double t = Number $ fromFloatDigits x
220+#else
221+ | Right (x, "") <- signed decimal t = Number $ I x
222+ | Right (x, "") <- double t = Number $ D x
223+#endif
214224 | otherwise = String t
215225 where x `isLike` ref = x `elem` [ref, T.toUpper ref, titleCased]
216226 where titleCased = toUpper (T.head ref) `T.cons` T.tail ref
yaml.cabal+2−1
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.8.5.3
2+version: 0.8.5.4
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -49,6 +49,7 @@ library
4949 , vector
5050 , text
5151 , attoparsec
52+ , scientific
5253 exposed-modules: Text.Libyaml
5354 Data.Yaml
5455 ghc-options: -Wall