@@ -147,7 +147,7 @@ instance FromFormKey a => FromFormKey (Product a) where parseFormKey = fmap Prod
148-- | The contents of a form, not yet URL-encoded.
148-- | The contents of a form, not yet URL-encoded.
150−-- 'Form' can be URL-encoded with 'encodeForm' and URL-decoded with 'decodeForm'.
150+-- 'Form' can be URL-encoded with 'urlEncodeForm' and URL-decoded with 'urlDecodeForm'.
151newtype Form = Form { unForm :: HashMap Text [Text] }
151newtype Form = Form { unForm :: HashMap Text [Text] }
152 deriving (Eq, Read, Generic, Monoid)
152 deriving (Eq, Read, Generic, Monoid)
@@ -342,31 +342,31 @@ instance (GFromForm f) => GFromForm (M1 C x f) where
343-- Key-value pairs get encoded to @key=value@ and separated by @&@:
343-- Key-value pairs get encoded to @key=value@ and separated by @&@:
345−-- >>> encodeForm [("name", "Julian"), ("lastname", "Arni")]
345+-- >>> urlEncodeForm [("name", "Julian"), ("lastname", "Arni")]
346-- "lastname=Arni&name=Julian"
346-- "lastname=Arni&name=Julian"
348-- Keys with empty values get encoded to just @key@ (without the @=@ sign):
348-- Keys with empty values get encoded to just @key@ (without the @=@ sign):
350−-- >>> encodeForm [("is_test", "")]
350+-- >>> urlEncodeForm [("is_test", "")]
351-- "is_test"
351-- "is_test"
353-- Empty keys are allowed too:
353-- Empty keys are allowed too:
355−-- >>> encodeForm [("", "foobar")]
355+-- >>> urlEncodeForm [("", "foobar")]
356-- "=foobar"
356-- "=foobar"
358-- However, if not key and value are empty, the key-value pair is ignored.
358-- However, if not key and value are empty, the key-value pair is ignored.
359−-- (This prevents @'decodeForm' . 'encodeForm'@ from being a true isomorphism).
359+-- (This prevents @'urlDecodeForm' . 'urlEncodeForm'@ from being a true isomorphism).
361−-- >>> encodeForm [("", "")]
361+-- >>> urlEncodeForm [("", "")]
364-- Everything is escaped with @'escapeURIString' 'isUnreserved'@:
364-- Everything is escaped with @'escapeURIString' 'isUnreserved'@:
366−-- >>> encodeForm [("fullname", "Andres Löh")]
366+-- >>> urlEncodeForm [("fullname", "Andres Löh")]
367-- "fullname=Andres%20L%C3%B6h"
367-- "fullname=Andres%20L%C3%B6h"
368−encodeForm :: Form -> BSL.ByteString
368+urlEncodeForm :: Form -> BSL.ByteString
369−encodeForm xs = BSL.intercalate "&" $ map (BSL.fromStrict . encodePair) $ toList xs
369+urlEncodeForm xs = BSL.intercalate "&" $ map (BSL.fromStrict . encodePair) $ toList xs
371 escape = Text.encodeUtf8 . Text.pack . escapeURIString isUnreserved . Text.unpack
371 escape = Text.encodeUtf8 . Text.pack . escapeURIString isUnreserved . Text.unpack
@@ -378,35 +378,35 @@ encodeForm xs = BSL.intercalate "&" $ map (BSL.fromStrict . encodePair) $ toList
379-- Key-value pairs get decoded normally:
379-- Key-value pairs get decoded normally:
381−-- >>> decodeForm "name=Greg&lastname=Weber"
381+-- >>> urlDecodeForm "name=Greg&lastname=Weber"
382-- Right (fromList [("lastname","Weber"),("name","Greg")])
382-- Right (fromList [("lastname","Weber"),("name","Greg")])
384-- Keys with no values get decoded to pairs with empty values.
384-- Keys with no values get decoded to pairs with empty values.
386−-- >>> decodeForm "is_test"
386+-- >>> urlDecodeForm "is_test"
387-- Right (fromList [("is_test","")])
387-- Right (fromList [("is_test","")])
389-- Empty keys are allowed:
389-- Empty keys are allowed:
391−-- >>> decodeForm "=foobar"
391+-- >>> urlDecodeForm "=foobar"
392-- Right (fromList [("","foobar")])
392-- Right (fromList [("","foobar")])
394-- The empty string gets decoded into an empty 'Form':
394-- The empty string gets decoded into an empty 'Form':
396−-- >>> decodeForm ""
396+-- >>> urlDecodeForm ""
397-- Right (fromList [])
397-- Right (fromList [])
399-- Everything is un-escaped with 'unEscapeString':
399-- Everything is un-escaped with 'unEscapeString':
401−-- >>> decodeForm "fullname=Andres%20L%C3%B6h"
401+-- >>> urlDecodeForm "fullname=Andres%20L%C3%B6h"
402-- Right (fromList [("fullname","Andres L\246h")])
402-- Right (fromList [("fullname","Andres L\246h")])
404-- Improperly formed strings result in an error:
404-- Improperly formed strings result in an error:
406−-- >>> decodeForm "this=has=too=many=equals"
406+-- >>> urlDecodeForm "this=has=too=many=equals"
407-- Left "not a valid pair: this=has=too=many=equals"
407-- Left "not a valid pair: this=has=too=many=equals"
408−decodeForm :: BSL.ByteString -> Either Text Form
408+urlDecodeForm :: BSL.ByteString -> Either Text Form
409−decodeForm bs = toForm <$> traverse parsePair pairs
409+urlDecodeForm bs = toForm <$> traverse parsePair pairs
411 pairs = map (Text.decodeUtf8With lenientDecode . BSL.toStrict) (BSL8.split '&' bs)
411 pairs = map (Text.decodeUtf8With lenientDecode . BSL.toStrict) (BSL8.split '&' bs)
@@ -425,23 +425,23 @@ data Proxy3 a b c = Proxy3
425-- @application/x-www-form-urlencoded@ 'BSL.ByteString' directly to a datatype
425-- @application/x-www-form-urlencoded@ 'BSL.ByteString' directly to a datatype
426-- that has an instance of 'FromForm'.
426-- that has an instance of 'FromForm'.
428−-- This is effectively @'fromForm' '<=<' 'decodeForm'@.
428+-- This is effectively @'fromForm' '<=<' 'urlDecodeForm'@.
430−-- >>> decodeAsForm "name=Dennis&age=22" :: Either Text Person
430+-- >>> urlDecodeAsForm "name=Dennis&age=22" :: Either Text Person
431-- Right (Person {name = "Dennis", age = 22})
431-- Right (Person {name = "Dennis", age = 22})
432−decodeAsForm :: FromForm a => BSL.ByteString -> Either Text a
432+urlDecodeAsForm :: FromForm a => BSL.ByteString -> Either Text a
433−decodeAsForm = fromForm <=< decodeForm
433+urlDecodeAsForm = fromForm <=< urlDecodeForm
435-- | This is a convenience function for encoding a datatype that has instance
435-- | This is a convenience function for encoding a datatype that has instance
436-- of 'ToForm' directly to a @application/x-www-form-urlencoded@
436-- of 'ToForm' directly to a @application/x-www-form-urlencoded@
437-- 'BSL.ByteString'.
437-- 'BSL.ByteString'.
439−-- This is effectively @'encodeForm' . 'toForm'@.
439+-- This is effectively @'urlEncodeForm' . 'toForm'@.
441−-- >>> encodeAsForm Person {name = "Dennis", age = 22}
441+-- >>> urlEncodeAsForm Person {name = "Dennis", age = 22}
442-- "age=22&name=Dennis"
442-- "age=22&name=Dennis"
443−encodeAsForm :: ToForm a => a -> BSL.ByteString
443+urlEncodeAsForm :: ToForm a => a -> BSL.ByteString
444−encodeAsForm = encodeForm . toForm
444+urlEncodeAsForm = urlEncodeForm . toForm
446-- | Find all values corresponding to a given key in a 'Form'.
446-- | Find all values corresponding to a given key in a 'Form'.