From f2d3e7fa9d2ec7abf6d0a8aedafc2c228f538afe Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 28 Apr 2020 21:37:18 +0200 Subject: Notmuch: handle JSON with broken UTF-8 --- Data/Aeson/Extends.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Data/Aeson/Extends.hs (limited to 'Data') 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 + -- cgit v1.2.3