@@ -10,6 +10,7 @@ import Data.Aeson.Encode (encodeToTextBuilder)
10import Data.Aeson.TH (deriveJSON)
10import Data.Aeson.TH (deriveJSON)
11import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
11import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
12import Data.Char (toUpper)
12import Data.Char (toUpper)
13+import Data.Maybe (fromMaybe)
13import Data.Time (UTCTime)
14import Data.Time (UTCTime)
14import Data.Time.Format (parseTime)
15import Data.Time.Format (parseTime)
15import GHC.Generics (Generic)
16import GHC.Generics (Generic)
@@ -52,6 +53,7 @@ tests = testGroup "unit" [
52 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
53 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
53 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
54 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
54 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
55 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
56+ , testGroup "Issue #351" $ fmap (testCase "-") issue351
57roundTripCamel :: String -> Assertion
59roundTripCamel :: String -> Assertion
@@ -218,6 +220,21 @@ jsonDecoding = [
218 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
220 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
223+------------------------------------------------------------------------------
225+------------------------------------------------------------------------------
227+-- A regression test for: https://github.com/bos/aeson/issues/351
228+overlappingRegression :: FromJSON a => L.ByteString -> [a]
229+overlappingRegression bs = fromMaybe [] $ decode bs
231+issue351 :: [Assertion]
233+ assertEqual "Int" ([1, 2, 3] :: [Int]) $ overlappingRegression "[1, 2, 3]"
234+ , assertEqual "Char" ("" :: String) $ overlappingRegression "\"abc\""
235+ , assertEqual "Char" ("abc" :: String) $ overlappingRegression "[\"a\", \"b\", \"c\"]"
221------------------------------------------------------------------------------
238------------------------------------------------------------------------------
222-- Comparison between bytestring and text encoders
239-- Comparison between bytestring and text encoders
223------------------------------------------------------------------------------
240------------------------------------------------------------------------------