git.iko.soy/typeable/http-api-data
on master help sign in
Remove utf8-string dependency
commit6e9716805769637f0f241758713a5bbc84d5d179 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateMon 29 Aug 2016, 17:09 (10 years ago) parent9b7a61d
2 files changed+9−11
http-api-data.cabal−1 src/Web/Internal/FormUrlEncoded.hs+9−10
http-api-data.cabal−1
@@ -30,7 +30,6 @@ library
3030 , time
3131 , time-locale-compat >=0.1.1.0 && <0.2
3232 , network-uri >= 2.6 && < 2.7
33− , utf8-string >= 1
3433 if flag(use-text-show)
3534 cpp-options: -DUSE_TEXT_SHOW
3635 build-depends: text-show >= 2
src/Web/Internal/FormUrlEncoded.hs+9−10
@@ -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--