@@ -11,6 +11,7 @@ import Data.Aeson.Internal (JSONPathElement(..), formatError)
1111import Data.Aeson.TH (deriveJSON)
1212import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
1313import Data.Char (toUpper)
14+import Data.Maybe (fromMaybe)
1415import Data.Time (UTCTime)
1516import Data.Time.Format (parseTime)
1617import GHC.Generics (Generic)
@@ -56,6 +57,7 @@ tests = testGroup "unit" [
5657 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
5758 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
5859 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
60+ , testGroup "Issue #351" $ fmap (testCase "-") issue351
5961 ]
6062
6163roundTripCamel :: String -> Assertion
@@ -229,6 +231,21 @@ jsonDecoding = [
229231 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
230232 ]
231233
234+------------------------------------------------------------------------------
235+-- Regressions
236+------------------------------------------------------------------------------
237+
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
241+
242+issue351 :: [Assertion]
243+issue351 = [
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\"]"
247+ ]
248+
232249------------------------------------------------------------------------------
233250-- Comparison between bytestring and text encoders
234251------------------------------------------------------------------------------