packages feed

lens-aeson 1.2 → 1.2.1

raw patch · 3 files changed

+34/−3 lines, 3 filesdep ~aesondep ~vector

Dependency ranges changed: aeson, vector

Files

CHANGELOG.markdown view
@@ -1,3 +1,11 @@+1.2.1 [2022.05.07]+------------------+* Change the `IsKey` instances for `ByteString`s to use+  `decodeUtf8With lenientDecode` instead of `decodeUtf8`. While these `IsKey`+  instances are meant to used for interoperability with `aeson` values that+  are UTF-8–encoded, using `decodeUtf8With lenientDecode` at least ensures+  that converting a non–UTF-8–encoded `ByteString` will not crash.+ 1.2 [2022.03.19] ---------------- * Require `aeson-2.0.2.*` and `lens-5.0.*` or greater.
lens-aeson.cabal view
@@ -1,6 +1,6 @@ name:          lens-aeson category:      Numeric-version:       1.2+version:       1.2.1 license:       MIT cabal-version: >= 1.10 license-file:  LICENSE
src/Data/Aeson/Lens.hs view
@@ -60,6 +60,7 @@ import qualified Data.ByteString as Strict import Data.ByteString.Lazy.Char8 as Lazy hiding (putStrLn) import Data.Text as Text+import qualified Data.Text.Encoding.Error as Encoding import qualified Data.Text.Lazy as LazyText import Data.Text.Short (ShortText) import Data.Text.Lens (packed)@@ -72,7 +73,9 @@ -- >>> import Control.Lens -- >>> import Data.Aeson -- >>> import Data.Text (Text)+-- >>> import qualified Data.ByteString as Strict (ByteString) -- >>> import Data.ByteString.Char8 as Strict.Char8+-- >>> import qualified Data.ByteString.Lazy as Lazy (ByteString) -- >>> import qualified Data.Vector as Vector -- >>> :set -XOverloadedStrings @@ -312,10 +315,10 @@ strictUtf8 = packed . strictTextUtf8  strictTextUtf8 :: Iso' Text.Text Strict.ByteString-strictTextUtf8 = iso StrictText.encodeUtf8 StrictText.decodeUtf8+strictTextUtf8 = iso StrictText.encodeUtf8 (StrictText.decodeUtf8With Encoding.lenientDecode)  lazyTextUtf8 :: Iso' LazyText.Text Lazy.ByteString-lazyTextUtf8 = iso LazyText.encodeUtf8 LazyText.decodeUtf8+lazyTextUtf8 = iso LazyText.encodeUtf8 (LazyText.decodeUtf8With Encoding.lenientDecode)  _JSON' :: (AsJSON t, FromJSON a, ToJSON a) => Prism' t a _JSON' = _JSON@@ -355,10 +358,30 @@   _Key = iso Key.fromShortText Key.toShortText   {-# INLINE _Key #-} +-- | This instance assumes that you are dealing with UTF-8–encoded+-- 'Strict.ByteString's, as this is the encoding that RFC 8259 requires JSON+-- values to use. As such, this is not a full 'Iso', since non–UTF-8–encoded+-- 'Strict.ByteString's will not roundtrip:+--+-- >>> let str = view _Key ("\255" :: Strict.ByteString)+-- >>> str+-- "\65533"+-- >>> view (from _Key) str :: Strict.ByteString+-- "\239\191\189" instance IsKey Strict.ByteString where   _Key = from strictTextUtf8._Key   {-# INLINE _Key #-} +-- | This instance assumes that you are dealing with UTF-8–encoded+-- 'Lazy.ByteString's, as this is the encoding that RFC 8259 requires JSON+-- values to use. As such, this is not a full 'Iso', since non–UTF-8–encoded+-- 'Lazy.ByteString's will not roundtrip:+--+-- >>> let str = view _Key ("\255" :: Lazy.ByteString)+-- >>> str+-- "\65533"+-- >>> view (from _Key) str :: Lazy.ByteString+-- "\239\191\189" instance IsKey Lazy.ByteString where   _Key = from lazyTextUtf8._Key   {-# INLINE _Key #-}