diff --git a/Web/Scotty/Route.hs b/Web/Scotty/Route.hs index 1005d01b..f140159c 100644 --- a/Web/Scotty/Route.hs +++ b/Web/Scotty/Route.hs @@ -113,7 +113,7 @@ matchRoute :: RoutePattern -> Request -> Maybe [Param] matchRoute (Literal pat) req | pat == path req = Just [] | otherwise = Nothing matchRoute (Function fun) req = fun req -matchRoute (Capture pat) req = go (T.split (=='/') pat) (compress $ T.split (=='/') $ path req) [] +matchRoute (Capture pat) req = go (T.split (=='/') pat) (compress $ "":pathInfo req) [] -- add empty segment to simulate being at the root where go [] [] prs = Just prs -- request string and pattern match! go [] r prs | T.null (mconcat r) = Just prs -- in case request has trailing slashes | otherwise = Nothing -- request string is longer than pattern diff --git a/test/Web/ScottySpec.hs b/test/Web/ScottySpec.hs index 04389bc6..011a27b4 100644 --- a/test/Web/ScottySpec.hs +++ b/test/Web/ScottySpec.hs @@ -56,6 +56,10 @@ spec = do it ("properly handles extra slash routes for " ++ method ++ " requests") $ do makeRequest "//scotty" `shouldRespondWith` 200 + withApp (route "/:paramName" $ captureParam "paramName" >>= text) $ do + it ("captures route parameters for " ++ method ++ " requests with url encoded '/' in path") $ do + makeRequest "/a%2Fb" `shouldRespondWith` "a/b" + describe "addroute" $ do forM_ availableMethods $ \method -> do withApp (addroute method "/scotty" $ html "") $ do