Merge pull request #1617 from league/url-encode
URL-encode POST parameters in yesod-test
This commit is contained in:
commit
d7a29977bf
@ -1,5 +1,11 @@
|
|||||||
# ChangeLog for yesod-test
|
# ChangeLog for yesod-test
|
||||||
|
|
||||||
|
## 1.6.6.2
|
||||||
|
|
||||||
|
addPostParam will now URL-encode keys and values to prevent corruption
|
||||||
|
when special characters such as `&` are used
|
||||||
|
[#1617](https://github.com/yesodweb/yesod/pull/1617)
|
||||||
|
|
||||||
## 1.6.6.1
|
## 1.6.6.1
|
||||||
|
|
||||||
* Documentation fixes
|
* Documentation fixes
|
||||||
|
|||||||
@ -1266,14 +1266,14 @@ request reqBuilder = do
|
|||||||
([ ("Cookie", cookieValue) ] ++ headersForPostData rbdPostData)
|
([ ("Cookie", cookieValue) ] ++ headersForPostData rbdPostData)
|
||||||
method extraHeaders urlPath urlQuery)
|
method extraHeaders urlPath urlQuery)
|
||||||
simpleRequestBody' (MultipleItemsPostData x) =
|
simpleRequestBody' (MultipleItemsPostData x) =
|
||||||
BSL8.fromChunks $ return $ TE.encodeUtf8 $ T.intercalate "&"
|
BSL8.fromChunks $ return $ H.renderSimpleQuery False
|
||||||
$ map singlepartPart x
|
$ concatMap singlepartPart x
|
||||||
simpleRequestBody' (BinaryPostData x) = x
|
simpleRequestBody' (BinaryPostData x) = x
|
||||||
cookieValue = Builder.toByteString $ Cookie.renderCookies cookiePairs
|
cookieValue = Builder.toByteString $ Cookie.renderCookies cookiePairs
|
||||||
cookiePairs = [ (Cookie.setCookieName c, Cookie.setCookieValue c)
|
cookiePairs = [ (Cookie.setCookieName c, Cookie.setCookieValue c)
|
||||||
| c <- map snd $ M.toList cookies ]
|
| c <- map snd $ M.toList cookies ]
|
||||||
singlepartPart (ReqFilePart _ _ _ _) = ""
|
singlepartPart (ReqFilePart _ _ _ _) = []
|
||||||
singlepartPart (ReqKvPart k v) = T.concat [k,"=",v]
|
singlepartPart (ReqKvPart k v) = [(TE.encodeUtf8 k, TE.encodeUtf8 v)]
|
||||||
|
|
||||||
-- If the request appears to be submitting a form (has key-value pairs) give it the form-urlencoded Content-Type.
|
-- If the request appears to be submitting a form (has key-value pairs) give it the form-urlencoded Content-Type.
|
||||||
-- The previous behavior was to always use the form-urlencoded Content-Type https://github.com/yesodweb/yesod/issues/1063
|
-- The previous behavior was to always use the form-urlencoded Content-Type https://github.com/yesodweb/yesod/issues/1063
|
||||||
|
|||||||
@ -145,9 +145,11 @@ main = hspec $ do
|
|||||||
request $ do
|
request $ do
|
||||||
setMethod "POST"
|
setMethod "POST"
|
||||||
setUrl $ LiteAppRoute ["post"]
|
setUrl $ LiteAppRoute ["post"]
|
||||||
addPostParam "foo" "foobarbaz"
|
-- If value uses special characters,
|
||||||
|
addPostParam "foo" "foo+bar%41<&baz"
|
||||||
statusIs 200
|
statusIs 200
|
||||||
bodyEquals "foobarbaz"
|
-- They pass through the server correctly.
|
||||||
|
bodyEquals "foo+bar%41<&baz"
|
||||||
yit "labels" $ do
|
yit "labels" $ do
|
||||||
get ("/form" :: Text)
|
get ("/form" :: Text)
|
||||||
statusIs 200
|
statusIs 200
|
||||||
@ -155,11 +157,13 @@ main = hspec $ do
|
|||||||
request $ do
|
request $ do
|
||||||
setMethod "POST"
|
setMethod "POST"
|
||||||
setUrl ("/form" :: Text)
|
setUrl ("/form" :: Text)
|
||||||
byLabel "Some Label" "12345"
|
byLabel "Some Label" "foo+bar%41<&baz"
|
||||||
fileByLabel "Some File" "test/main.hs" "text/plain"
|
fileByLabel "Some File" "test/main.hs" "text/plain"
|
||||||
addToken
|
addToken
|
||||||
statusIs 200
|
statusIs 200
|
||||||
bodyEquals "12345"
|
-- The '<' and '&' get encoded to HTML entities because
|
||||||
|
-- "/form" (unlike "/post") uses toHtml.
|
||||||
|
bodyEquals "foo+bar%41<&baz"
|
||||||
yit "labels WForm" $ do
|
yit "labels WForm" $ do
|
||||||
get ("/wform" :: Text)
|
get ("/wform" :: Text)
|
||||||
statusIs 200
|
statusIs 200
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-test
|
name: yesod-test
|
||||||
version: 1.6.6.1
|
version: 1.6.6.2
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Nubis <nubis@woobiz.com.ar>
|
author: Nubis <nubis@woobiz.com.ar>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user