Skip to content

Commit

Permalink
Fix handling of encoded slash in url path (#302)
Browse files Browse the repository at this point in the history
* Fix handling of encoded slash in url path

* Add test

* Fix: remove unnecessary fromStrict

* Fix: replace obsolete use of 'param'
  • Loading branch information
jfraudeau authored Dec 17, 2023
1 parent c1eb32b commit e036cbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Web/Scotty/Route.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,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
Expand Down
4 changes: 4 additions & 0 deletions test/Web/ScottySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e036cbc

Please sign in to comment.