diff --git a/Test/CleanPath.hs b/Test/CleanPath.hs index f00c7c93..d6248ff2 100644 --- a/Test/CleanPath.hs +++ b/Test/CleanPath.hs @@ -38,6 +38,7 @@ mkYesod "Y" [$parseRoutes| /foo/#String FooStringR GET /bar BarR GET /subsite SubsiteR Subsite getSubsite +/plain PlainR GET |] instance Yesod Y where @@ -54,6 +55,7 @@ instance Yesod Y where getFooR = return $ RepPlain "foo" getFooStringR = return . RepPlain . toContent getBarR = return $ RepPlain "bar" +getPlainR = return $ RepPlain "plain" cleanPathTest :: Test cleanPathTest = testGroup "Test.CleanPath" @@ -63,6 +65,7 @@ cleanPathTest = testGroup "Test.CleanPath" , testCase "has trailing slash" hasTrailingSlash , testCase "/foo/something" fooSomething , testCase "subsite dispatch" subsiteDispatch + , testCase "redirect with query string" redQueryString ] runner f = toWaiApp Y >>= runSession f @@ -119,3 +122,11 @@ subsiteDispatch = runner $ do assertStatus 200 res assertContentType "SUBSITE" res assertBody "[\"1\",\"2\",\"3\",\"\"]" res + +redQueryString = runner $ do + res <- request defaultRequest + { pathInfo = decodePathSegments "/plain/" + , rawQueryString = "?foo=bar" + } + assertStatus 301 res + assertHeader "Location" "http://test/plain?foo=bar" res diff --git a/Yesod/Internal/Dispatch.hs b/Yesod/Internal/Dispatch.hs index f8f073e8..9594b652 100644 --- a/Yesod/Internal/Dispatch.hs +++ b/Yesod/Internal/Dispatch.hs @@ -92,7 +92,6 @@ sendRedirect y segments' env = if S.null (W.rawQueryString env) then dest else (dest `mappend` - Blaze.ByteString.Builder.Char8.fromChar '?' `mappend` Blaze.ByteString.Builder.fromByteString (W.rawQueryString env)) mkYesodDispatch' :: [((String, Pieces), Maybe String)]