summaryrefslogtreecommitdiffstats
path: root/Data
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2020-04-28 21:37:18 +0200
committertv <tv@krebsco.de>2020-04-28 23:37:28 +0200
commitf2d3e7fa9d2ec7abf6d0a8aedafc2c228f538afe (patch)
tree42bc89c4afba0962c378b702cee7f7623a2b7be8 /Data
parentfa3e4365193857ecf78138d6e7aee55f38a61baa (diff)
Notmuch: handle JSON with broken UTF-8
Diffstat (limited to 'Data')
-rw-r--r--Data/Aeson/Extends.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Data/Aeson/Extends.hs b/Data/Aeson/Extends.hs
new file mode 100644
index 0000000..d78f81d
--- /dev/null
+++ b/Data/Aeson/Extends.hs
@@ -0,0 +1,15 @@
+module Data.Aeson.Extends (module Data.Aeson.Extends) where
+
+import Data.Aeson as Data.Aeson.Extends
+
+import qualified Data.ByteString.Lazy as LBS
+import qualified Data.Text.Encoding.Error as TE
+import qualified Data.Text.Lazy.Encoding as LT
+
+
+eitherDecodeLenient' :: FromJSON a => LBS.ByteString -> Either String a
+eitherDecodeLenient' s =
+ either (const $ eitherDecode' $ lenientReencode s) id (eitherDecode' s)
+ where
+ lenientReencode = LT.encodeUtf8 . LT.decodeUtf8With TE.lenientDecode
+