@@ -51,7 +51,7 @@ import Web.Internal.HttpApiData
51-- | The contents of a form, not yet URL-encoded.
51-- | The contents of a form, not yet URL-encoded.
53-- 'Form' can be URL-encoded with 'encodeForm' and URL-decoded with 'decodeForm'.
53-- 'Form' can be URL-encoded with 'encodeForm' and URL-decoded with 'decodeForm'.
54−newtype Form = Form { unForm :: Map Text Text }
54+newtype Form = Form { unForm :: Map Text [Text] }
55 deriving (Eq, Read, Generic, Monoid)
55 deriving (Eq, Read, Generic, Monoid)
57instance Show Form where
57instance Show Form where
@@ -60,8 +60,8 @@ instance Show Form where
61instance IsList Form where
61instance IsList Form where
62 type Item Form = (Text, Text)
62 type Item Form = (Text, Text)
63− fromList = Form . Map.fromList
63+ fromList = Form . Map.fromListWith (flip (<>)) . fmap (\(k, v) -> (k, [v]))
64− toList = Map.toList . unForm
64+ toList = concatMap (\(k, vs) -> map ((,) k) vs) . Map.toList . unForm
66-- | Convert a value into 'Form'.
66-- | Convert a value into 'Form'.
@@ -106,7 +106,7 @@ class ToForm a where
106 toForm = genericToForm
106 toForm = genericToForm
108instance ToForm [(Text, Text)] where toForm = fromList
108instance ToForm [(Text, Text)] where toForm = fromList
109−instance ToForm (Map Text Text) where toForm = Form
109+instance ToForm (Map Text [Text]) where toForm = Form . Map.filter (not . null)
110instance ToForm Form where toForm = id
110instance ToForm Form where toForm = id
112-- | A 'Generic'-based implementation of 'toForm'.
112-- | A 'Generic'-based implementation of 'toForm'.
@@ -177,8 +177,8 @@ class FromForm a where
177 fromForm = genericFromForm
177 fromForm = genericFromForm
179instance FromForm Form where fromForm = return
179instance FromForm Form where fromForm = return
180+instance FromForm (Map Text [Text]) where fromForm = return . unForm
180instance FromForm [(Text, Text)] where fromForm = return . toList
181instance FromForm [(Text, Text)] where fromForm = return . toList
181−instance FromForm (Map Text Text) where fromForm = return . unForm
183-- | A 'Generic'-based implementation of 'fromForm'.
183-- | A 'Generic'-based implementation of 'fromForm'.
184-- This is used as a default implementation in 'FromForm'.
184-- This is used as a default implementation in 'FromForm'.
@@ -202,9 +202,10 @@ instance (GFromForm f, GFromForm g) => GFromForm (f :+: g) where
203instance (Selector s, FromHttpApiData f) => GFromForm (M1 S s (K1 i f)) where
203instance (Selector s, FromHttpApiData f) => GFromForm (M1 S s (K1 i f)) where
204 gFromForm f =
204 gFromForm f =
205− case Map.lookup key (unForm f) of
205+ case concat (Map.lookup key (unForm f)) of
206− Nothing -> Left $ "Could not find key " <> Text.pack (show key)
207− Just v -> M1 . K1 <$> parseQueryParam v
206+ [v] -> M1 . K1 <$> parseQueryParam v
207+ [] -> Left $ "Could not find key " <> Text.pack (show key)
208+ _ -> Left $ "Duplicate key " <> Text.pack (show key)
209 key = Text.pack $ selName (Proxy3 :: Proxy3 s g p)
210 key = Text.pack $ selName (Proxy3 :: Proxy3 s g p)