Fix some character encoding bugs
This commit is contained in:
parent
9b816aec75
commit
bf3e8afefb
@ -319,7 +319,7 @@ assertNoHeader header = withResponse $ \ SResponse { simpleHeaders = h } ->
|
|||||||
bodyEquals :: String -> YesodExample site ()
|
bodyEquals :: String -> YesodExample site ()
|
||||||
bodyEquals text = withResponse $ \ res ->
|
bodyEquals text = withResponse $ \ res ->
|
||||||
liftIO $ HUnit.assertBool ("Expected body to equal " ++ text) $
|
liftIO $ HUnit.assertBool ("Expected body to equal " ++ text) $
|
||||||
(simpleBody res) == BSL8.pack text
|
(simpleBody res) == encodeUtf8 (TL.pack text)
|
||||||
|
|
||||||
-- | Assert the last response has the given text. The check is performed using the response
|
-- | Assert the last response has the given text. The check is performed using the response
|
||||||
-- body in full text form.
|
-- body in full text form.
|
||||||
@ -329,7 +329,7 @@ bodyContains text = withResponse $ \ res ->
|
|||||||
(simpleBody res) `contains` text
|
(simpleBody res) `contains` text
|
||||||
|
|
||||||
contains :: BSL8.ByteString -> String -> Bool
|
contains :: BSL8.ByteString -> String -> Bool
|
||||||
contains a b = DL.isInfixOf b (BSL8.unpack a)
|
contains a b = DL.isInfixOf b (TL.unpack $ decodeUtf8 a)
|
||||||
|
|
||||||
-- | Queries the html using a css selector, and all matched elements must contain
|
-- | Queries the html using a css selector, and all matched elements must contain
|
||||||
-- the given string.
|
-- the given string.
|
||||||
@ -364,7 +364,7 @@ htmlCount query count = do
|
|||||||
-- | Outputs the last response body to stderr (So it doesn't get captured by HSpec)
|
-- | Outputs the last response body to stderr (So it doesn't get captured by HSpec)
|
||||||
printBody :: YesodExample site ()
|
printBody :: YesodExample site ()
|
||||||
printBody = withResponse $ \ SResponse { simpleBody = b } ->
|
printBody = withResponse $ \ SResponse { simpleBody = b } ->
|
||||||
liftIO $ hPutStrLn stderr $ BSL8.unpack b
|
liftIO $ BSL8.hPutStrLn stderr b
|
||||||
|
|
||||||
-- | Performs a CSS query and print the matches to stderr.
|
-- | Performs a CSS query and print the matches to stderr.
|
||||||
printMatches :: Query -> YesodExample site ()
|
printMatches :: Query -> YesodExample site ()
|
||||||
@ -539,7 +539,7 @@ request reqBuilder = do
|
|||||||
, rbdGets = []
|
, rbdGets = []
|
||||||
, rbdHeaders = []
|
, rbdHeaders = []
|
||||||
}
|
}
|
||||||
let path = T.cons '/' $ T.intercalate "/" rbdPath
|
let path = TE.decodeUtf8 $ Builder.toByteString $ H.encodePathSegments rbdPath
|
||||||
|
|
||||||
-- expire cookies and filter them for the current path. TODO: support max age
|
-- expire cookies and filter them for the current path. TODO: support max age
|
||||||
currentUtc <- liftIO getCurrentTime
|
currentUtc <- liftIO getCurrentTime
|
||||||
@ -644,7 +644,7 @@ request reqBuilder = do
|
|||||||
, remoteHost = Sock.SockAddrInet 1 2
|
, remoteHost = Sock.SockAddrInet 1 2
|
||||||
, requestHeaders = headers ++ extraHeaders
|
, requestHeaders = headers ++ extraHeaders
|
||||||
, rawPathInfo = TE.encodeUtf8 urlPath
|
, rawPathInfo = TE.encodeUtf8 urlPath
|
||||||
, pathInfo = DL.filter (/="") $ T.split (== '/') urlPath
|
, pathInfo = H.decodePathSegments $ TE.encodeUtf8 urlPath
|
||||||
, rawQueryString = H.renderQuery False urlQuery
|
, rawQueryString = H.renderQuery False urlQuery
|
||||||
, queryString = urlQuery
|
, queryString = urlQuery
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
import Test.HUnit hiding (Test)
|
import Test.HUnit hiding (Test)
|
||||||
@ -13,6 +14,7 @@ import Text.XML
|
|||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
import Network.Wai (pathInfo)
|
||||||
|
|
||||||
import Data.ByteString.Lazy.Char8 ()
|
import Data.ByteString.Lazy.Char8 ()
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
@ -106,6 +108,15 @@ main = hspec $ do
|
|||||||
addNonce
|
addNonce
|
||||||
statusIs 200
|
statusIs 200
|
||||||
bodyEquals "12345"
|
bodyEquals "12345"
|
||||||
|
ydescribe "utf8 paths" $ do
|
||||||
|
yit "from path" $ do
|
||||||
|
get ("/dynamic1/שלום" :: Text)
|
||||||
|
statusIs 200
|
||||||
|
bodyEquals "שלום"
|
||||||
|
yit "from WAI" $ do
|
||||||
|
get ("/dynamic2/שלום" :: Text)
|
||||||
|
statusIs 200
|
||||||
|
bodyEquals "שלום"
|
||||||
|
|
||||||
instance RenderMessage LiteApp FormMessage where
|
instance RenderMessage LiteApp FormMessage where
|
||||||
renderMessage _ _ = defaultFormMessage
|
renderMessage _ _ = defaultFormMessage
|
||||||
@ -117,6 +128,10 @@ app = liteApp $ do
|
|||||||
case mfoo of
|
case mfoo of
|
||||||
Nothing -> return "Hello world!"
|
Nothing -> return "Hello world!"
|
||||||
Just foo -> return $ "foo=" <> foo
|
Just foo -> return $ "foo=" <> foo
|
||||||
|
onStatic "dynamic1" $ withDynamic $ \d -> dispatchTo $ return (d :: Text)
|
||||||
|
onStatic "dynamic2" $ onStatic "שלום" $ dispatchTo $ do
|
||||||
|
req <- waiRequest
|
||||||
|
return $ pathInfo req !! 1
|
||||||
onStatic "post" $ dispatchTo $ do
|
onStatic "post" $ dispatchTo $ do
|
||||||
mfoo <- lookupPostParam "foo"
|
mfoo <- lookupPostParam "foo"
|
||||||
case mfoo of
|
case mfoo of
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-test
|
name: yesod-test
|
||||||
version: 1.2.1.2
|
version: 1.2.1.3
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Nubis <nubis@woobiz.com.ar>
|
author: Nubis <nubis@woobiz.com.ar>
|
||||||
@ -59,6 +59,7 @@ test-suite test
|
|||||||
, yesod-core
|
, yesod-core
|
||||||
, yesod-form
|
, yesod-form
|
||||||
, text
|
, text
|
||||||
|
, wai
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user