@@ -10,6 +10,7 @@ import Data.Aeson.Encode (encodeToTextBuilder)
1010import Data.Aeson.TH (deriveJSON)
1111import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
1212import Data.Char (toUpper)
13+import Data.Maybe (fromMaybe)
1314import Data.Time (UTCTime)
1415import Data.Time.Format (parseTime)
1516import GHC.Generics (Generic)
@@ -52,6 +53,7 @@ tests = testGroup "unit" [
5253 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
5354 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
5455 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
56+ , testGroup "Issue #351" $ fmap (testCase "-") issue351
5557 ]
5658
5759roundTripCamel :: String -> Assertion
@@ -218,6 +220,21 @@ jsonDecoding = [
218220 , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
219221 ]
220222
223+------------------------------------------------------------------------------
224+-- Regressions
225+------------------------------------------------------------------------------
226+
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
230+
231+issue351 :: [Assertion]
232+issue351 = [
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\"]"
236+ ]
237+
221238------------------------------------------------------------------------------
222239-- Comparison between bytestring and text encoders
223240------------------------------------------------------------------------------