Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #110 from pheaver/topic/graceful-utf8-decode

detect invalid UTF-8 encoding in JSON strings, throw appropriate error
  • Loading branch information...
commit 9d76a7440592398463996387eed3ab78ced0eb56 2 parents fb81fbf + eca6450
@bos authored
Showing with 11 additions and 6 deletions.
  1. +11 −6 Data/Aeson/Parser/Internal.hs
View
17 Data/Aeson/Parser/Internal.hs
@@ -37,7 +37,7 @@ import Data.ByteString as B
import Data.Char (chr)
import Data.Monoid (mappend, mempty)
import Data.Text as T
-import Data.Text.Encoding (decodeUtf8)
+import Data.Text.Encoding (decodeUtf8')
import Data.Vector as Vector hiding ((++))
import Data.Word (Word8)
import qualified Data.Attoparsec as A
@@ -175,11 +175,16 @@ jstring_ = {-# SCC "jstring_" #-} do
then Nothing
else Just (c == backslash)
_ <- A.word8 doubleQuote
- if backslash `B.elem` s
- then case Z.parse unescape s of
- Right r -> return (decodeUtf8 r)
- Left err -> fail err
- else return (decodeUtf8 s)
+ s' <- if backslash `B.elem` s
+ then case Z.parse unescape s of
+ Right r -> return r
+ Left err -> fail err
+ else return s
+
+ case decodeUtf8' s' of
+ Right r -> return r
+ Left err -> fail $ show err
+
{-# INLINE jstring_ #-}
unescape :: Z.Parser ByteString
Please sign in to comment.
Something went wrong with that request. Please try again.