@@ -11,6 +11,7 @@ import Data.Aeson.Internal (JSONPathElement(..), formatError)
11import Data.Aeson.TH (deriveJSON)
11import Data.Aeson.TH (deriveJSON)
12import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
12import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
13import Data.Char (toUpper)
13import Data.Char (toUpper)
14+import Data.Maybe (fromMaybe)
14import Data.Time (UTCTime)
15import Data.Time (UTCTime)
15import Data.Time.Format (parseTime)
16import Data.Time.Format (parseTime)
16import GHC.Generics (Generic)
17import GHC.Generics (Generic)
@@ -56,6 +57,7 @@ tests = testGroup "unit" [
56 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
57 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
57 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
58 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
58 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
59 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
60+ , testGroup "Issue #351" $ fmap (testCase "-") issue351
61roundTripCamel :: String -> Assertion
63roundTripCamel :: String -> Assertion
@@ -229,6 +231,21 @@ jsonDecoding = [
229 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
231 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
234+------------------------------------------------------------------------------
236+------------------------------------------------------------------------------
238+-- A regression test for: https://github.com/bos/aeson/issues/351
239+overlappingRegression :: FromJSON a => L.ByteString -> [a]
240+overlappingRegression bs = fromMaybe [] $ decode bs
242+issue351 :: [Assertion]
244+ assertEqual "Int" ([1, 2, 3] :: [Int]) $ overlappingRegression "[1, 2, 3]"
245+ , assertEqual "Char" ("" :: String) $ overlappingRegression "\"abc\""
246+ , assertEqual "Char" ("abc" :: String) $ overlappingRegression "[\"a\", \"b\", \"c\"]"
232------------------------------------------------------------------------------
249------------------------------------------------------------------------------
233-- Comparison between bytestring and text encoders
250-- Comparison between bytestring and text encoders
234------------------------------------------------------------------------------
251------------------------------------------------------------------------------