yaml 0.11.1.0 → 0.11.1.1
raw patch · 4 files changed
+33/−17 lines, 4 filesdep ~scientificPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: scientific
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- src/Data/Yaml.hs +13/−10
- test/Data/YamlSpec.hs +9/−0
- yaml.cabal +7/−7
ChangeLog.md view
@@ -1,5 +1,9 @@ # ChangeLog for yaml +## 0.11.1.1++* Use the appropriate `Scientific` rendering function to avoid a memory overflow when rendering. The previously used function from `aeson` would not use scientific notation, and could use large amounts of memory for values such as `1e9999999999999`.+ ## 0.11.1.0 * Better error messages in the `Data.Yaml.Config` module [#168](https://github.com/snoyberg/yaml/issues/168)
src/Data/Yaml.hs view
@@ -94,22 +94,18 @@ , Object, Array , withObject, withText, withArray, withScientific, withBool )-#if MIN_VERSION_aeson(1,0,0)-import Data.Aeson.Text (encodeToTextBuilder)-#else-import Data.Aeson.Encode (encodeToTextBuilder)-#endif+import qualified Data.Scientific as S+import qualified Data.ByteString.Builder.Scientific import Data.Aeson.Types (Pair, parseMaybe, parseEither, Parser) import Data.ByteString (ByteString)+import qualified Data.ByteString.Builder as BB+import qualified Data.ByteString.Lazy as BL import Data.Conduit ((.|), runConduitRes) import qualified Data.Conduit.List as CL import qualified Data.HashMap.Strict as M import qualified Data.HashSet as HashSet import Data.Text.Encoding (encodeUtf8) import qualified Data.Text as T-import qualified Data.Text.Encoding as TE-import qualified Data.Text.Lazy as TL-import Data.Text.Lazy.Builder (toLazyText) import qualified Data.Vector as V import System.IO.Unsafe (unsafePerformIO) import Data.Text (Text)@@ -220,8 +216,15 @@ objToEvents' Null rest = EventScalar "null" NullTag PlainNoTag Nothing : rest objToEvents' (Bool True) rest = EventScalar "true" BoolTag PlainNoTag Nothing : rest objToEvents' (Bool False) rest = EventScalar "false" BoolTag PlainNoTag Nothing : rest- -- Use aeson's implementation which gets rid of annoying decimal points- objToEvents' n@Number{} rest = EventScalar (TE.encodeUtf8 $ TL.toStrict $ toLazyText $ encodeToTextBuilder n) IntTag PlainNoTag Nothing : rest++ objToEvents' (Number s) rest =+ let builder+ -- Special case the 0 exponent to remove the trailing .0+ | S.base10Exponent s == 0 = BB.integerDec $ S.coefficient s+ | otherwise = Data.ByteString.Builder.Scientific.scientificBuilder s+ lbs = BB.toLazyByteString builder+ bs = BL.toStrict lbs+ in EventScalar bs IntTag PlainNoTag Nothing : rest pairToEvents :: Pair -> [Y.Event] -> [Y.Event] pairToEvents (k, v) = objToEvents' (String k) . objToEvents' v
test/Data/YamlSpec.hs view
@@ -11,6 +11,7 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as B8 import Data.Int (Int64)+import qualified Data.Scientific as S import Test.HUnit hiding (Test, path) @@ -20,6 +21,7 @@ import Control.Monad import Control.Exception (try, SomeException) import Test.Hspec+import Test.Hspec.QuickCheck import Data.Either.Compat import System.Directory (createDirectory, createDirectoryIfMissing) import Test.Mockery.Directory@@ -309,6 +311,13 @@ , Y.EventSequenceEnd ] `shouldReturn` "[\"foo\", 99, 99.99, bar, !foo \"foo\", !foo foo]\n"++ prop "Scientific values round-trip" $ \coeff expon -> do+ let val = D.Number $ S.scientific coeff expon+ let rendered = D.encode val+ case D.decodeEither' rendered of+ Left e -> error $ show (coeff, expon, e)+ Right val' -> val' `shouldBe` val specialStrings :: [T.Text] specialStrings =
yaml.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 3a4f2b1c1a7a978d5810ea6223b95b1c51f38f60610704c35e28f8bc667081ba+-- hash: 9426dfc0830aba34ef783254b6e2e389a47c1723b5b350378944dce20e062b50 name: yaml-version: 0.11.1.0+version: 0.11.1.1 synopsis: Support for parsing and rendering YAML documents. description: README and API documentation are available at <https://www.stackage.org/package/yaml> category: Data@@ -76,7 +76,7 @@ , libyaml >=0.1 && <0.2 , mtl , resourcet >=0.3 && <1.3- , scientific+ , scientific >=0.3 , template-haskell , text , transformers >=0.1@@ -108,7 +108,7 @@ , libyaml >=0.1 && <0.2 , mtl , resourcet >=0.3 && <1.3- , scientific+ , scientific >=0.3 , template-haskell , text , transformers >=0.1@@ -143,7 +143,7 @@ , libyaml >=0.1 && <0.2 , mtl , resourcet >=0.3 && <1.3- , scientific+ , scientific >=0.3 , template-haskell , text , transformers >=0.1@@ -175,7 +175,7 @@ , libyaml >=0.1 && <0.2 , mtl , resourcet >=0.3 && <1.3- , scientific+ , scientific >=0.3 , template-haskell , text , transformers >=0.1@@ -218,7 +218,7 @@ , mtl , raw-strings-qq , resourcet >=0.3 && <1.3- , scientific+ , scientific >=0.3 , template-haskell , temporary , text