@@ -19,11 +19,10 @@ import Control.Applicative
1919import Control.Arrow (first, second)
2020import Control.Monad.State
2121import qualified Data.ByteString.Lazy as BSL
22−import qualified Data.ByteString.Lazy.UTF8 as BSLUTF8
2322import qualified Data.Map as M
2423import Data.Monoid
2524import qualified Data.Text as T
26−import Data.Text.Encoding (decodeUtf8With)
25+import Data.Text.Encoding (decodeUtf8With, encodeUtf8)
2726import Data.Text.Encoding.Error (lenientDecode)
2827import GHC.Exts (IsList (..))
2928import GHC.Generics
@@ -191,7 +190,7 @@ class FromForm a where
191190 fromForm = genericFromForm
192191
193192instance FromForm Form where fromForm = return
194−instance FromForm [(T.Text, T.Text)] where fromForm = toList
193+instance FromForm [(T.Text, T.Text)] where fromForm = return . toList
195194instance FromForm (M.Map T.Text T.Text) where fromForm = return . unForm
196195
197196-- | A 'Generic'-based implementation of 'fromForm'.
@@ -256,13 +255,13 @@ instance (GFromForm f) => GFromForm (M1 C x f) where
256255-- >>> encodeForm [("fullname", "Andres Löh")]
257256-- "fullname=Andres%20L%C3%B6h"
258257encodeForm :: Form -> BSL.ByteString
259−encodeForm xs =
260− let escape :: T.Text -> BSL.ByteString
261− escape = BSLUTF8.fromString . escapeURIString isUnreserved . T.unpack
262− encodePair :: (T.Text, T.Text) -> BSL.ByteString
263− encodePair (k, "") = escape k
264− encodePair (k, v) = escape k <> "=" <> escape v
265− in BSL.intercalate "&" $ map encodePair $ toList xs
258+encodeForm xs = BSL.intercalate "&" $ map (BSL.fromStrict . encodePair) $ toList xs
259+ where
260+ escape = encodeUtf8 . T.pack . escapeURIString isUnreserved . T.unpack
261+
262+ encodePair (k, "") = escape k
263+ encodePair (k, v) = escape k <> "=" <> escape v
264+
266265
267266-- | Decode an @application/x-www-form-urlencoded@ 'BSL.ByteString' to a 'Form'.
268267--