@@ -8,10 +8,11 @@ module Tests.Regressions
88
99import Control.Exception (SomeException, handle)
1010import System.IO
11−import Test.HUnit (assertFailure)
11+import Test.HUnit (assertBool, assertFailure)
1212import qualified Data.ByteString as B
1313import qualified Data.ByteString.Lazy as LB
1414import qualified Data.Text as T
15+import qualified Data.Text.Encoding as TE
1516import qualified Data.Text.IO as T
1617import qualified Data.Text.Lazy as LT
1718import qualified Data.Text.Lazy.Encoding as LE
@@ -49,9 +50,18 @@ replicate_crash = handle (\(_::SomeException) -> return ()) $
4950 power | maxBound == (2147483647::Int) = 28
5051 | otherwise = 60 :: Int
5152
53+-- Reported by John Millikin: a UTF-8 decode error handler could
54+-- return a bogus substitution character, which we would write without
55+-- checking.
56+utf8_decode_unsafe :: IO ()
57+utf8_decode_unsafe = do
58+ let t = TE.decodeUtf8With (\_ _ -> Just '\xdc00') "\x80"
59+ assertBool "broken error recovery shouldn't break us" (t == "\xfffd")
60+
5261tests :: F.Test
5362tests = F.testGroup "Regressions"
5463 [ F.testCase "hGetContents_crash" hGetContents_crash
5564 , F.testCase "lazy_encode_crash" lazy_encode_crash
5665 , F.testCase "replicate_crash" replicate_crash
66+ , F.testCase "utf8_decode_unsafe" utf8_decode_unsafe
5767 ]