git.iko.soy/typeable/http-api-data
on master help sign in
Use a custom Show instanse for Form (like Map has)
6ab8a56Nickolay Kudasov
src/Web/HttpApiData/Internal/FormUrlEncoded.hs+15−11
@@ -49,7 +49,11 @@ import Web.HttpApiData.Internal.HttpApiData
49--
49--
50-- 'Form' can be URL-encoded with 'encodeForm' and URL-decoded with 'decodeForm'.
50-- 'Form' can be URL-encoded with 'encodeForm' and URL-decoded with 'decodeForm'.
51newtype Form = Form { unForm :: M.Map T.Text T.Text }
51newtype Form = Form { unForm :: M.Map T.Text T.Text }
52− deriving (Eq, Show, Read, Generic, Monoid)
52+ deriving (Eq, Read, Generic, Monoid)
53+
54+instance Show Form where
55+ showsPrec d form = showParen (d > 10) $
56+ showString "fromList " . shows (toList form)
53
57
54instance IsList Form where
58instance IsList Form where
55 type Item Form = (T.Text, T.Text)
59 type Item Form = (T.Text, T.Text)
@@ -264,28 +268,28 @@ encodeForm xs =
264--
268--
265-- Key-value pairs get decoded normally:
269-- Key-value pairs get decoded normally:
266--
270--
267−-- >>> toList <$> decodeForm "name=Greg&lastname=Weber"
271+-- >>> decodeForm "name=Greg&lastname=Weber"
268−-- Right [("lastname","Weber"),("name","Greg")]
272+-- Right (fromList [("lastname","Weber"),("name","Greg")])
269--
273--
270-- Keys with no values get decoded to pairs with empty values.
274-- Keys with no values get decoded to pairs with empty values.
271--
275--
272−-- >>> toList <$> decodeForm "is_test"
276+-- >>> decodeForm "is_test"
273−-- Right [("is_test","")]
277+-- Right (fromList [("is_test","")])
274--
278--
275-- Empty keys are allowed:
279-- Empty keys are allowed:
276--
280--
277−-- >>> toList <$> decodeForm "=foobar"
281+-- >>> decodeForm "=foobar"
278−-- Right [("","foobar")]
282+-- Right (fromList [("","foobar")])
279--
283--
280-- The empty string gets decoded into an empty 'Form':
284-- The empty string gets decoded into an empty 'Form':
281--
285--
282−-- >>> toList <$> decodeForm ""
286+-- >>> decodeForm ""
283−-- Right []
287+-- Right (fromList [])
284--
288--
285-- Everything is un-escaped with 'unEscapeString':
289-- Everything is un-escaped with 'unEscapeString':
286--
290--
287−-- >>> toList <$> decodeForm "fullname=Andres%20L%C3%B6h"
291+-- >>> decodeForm "fullname=Andres%20L%C3%B6h"
288−-- Right [("fullname","Andres L\246h")]
292+-- Right (fromList [("fullname","Andres L\246h")])
289--
293--
290-- Improperly formed strings result in an error:
294-- Improperly formed strings result in an error:
291--
295--