yesod-test: correction to PR for multipart

This commit is contained in:
Christopher League 2019-08-13 11:58:11 -04:00
parent 3f98190645
commit 08a9632eba
2 changed files with 8 additions and 9 deletions

View File

@ -1242,9 +1242,8 @@ request reqBuilder = do
BS8.concat $ separator : [BS8.concat [multipartPart p, separator] | p <- parts]
multipartPart (ReqKvPart k v) = BS8.concat
[ "Content-Disposition: form-data; "
, "name=\"", enc k, "\"\r\n\r\n"
, enc v, "\r\n"]
where enc = H.urlEncode False . TE.encodeUtf8
, "name=\"", TE.encodeUtf8 k, "\"\r\n\r\n"
, TE.encodeUtf8 v, "\r\n"]
multipartPart (ReqFilePart k v bytes mime) = BS8.concat
[ "Content-Disposition: form-data; "
, "name=\"", TE.encodeUtf8 k, "\"; "

View File

@ -146,10 +146,10 @@ main = hspec $ do
setMethod "POST"
setUrl $ LiteAppRoute ["post"]
-- If value uses special characters,
addPostParam "foo" "foo+bar%41&baz"
addPostParam "foo" "foo+bar%41<&baz"
statusIs 200
-- They pass through the server correctly.
bodyEquals "foo+bar%41&baz"
bodyEquals "foo+bar%41<&baz"
yit "labels" $ do
get ("/form" :: Text)
statusIs 200
@ -157,13 +157,13 @@ main = hspec $ do
request $ do
setMethod "POST"
setUrl ("/form" :: Text)
byLabel "Some Label" "foo+bar%41&baz"
byLabel "Some Label" "foo+bar%41<&baz"
fileByLabel "Some File" "test/main.hs" "text/plain"
addToken
statusIs 200
-- The '%', '&' get further encoded because "/form"
-- (unlike "/post") uses toHtml.
bodyEquals "foo+bar%2541&amp;baz"
-- The '<' and '&' get encoded to HTML entities because
-- "/form" (unlike "/post") uses toHtml.
bodyEquals "foo+bar%41&lt;&amp;baz"
yit "labels WForm" $ do
get ("/wform" :: Text)
statusIs 200