Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of encoded slash in url path #302

Merged
merged 5 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Web/Scotty/Route.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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 $ T.fromStrict <$> "":pathInfo req) [] -- add empty segment to simulate being at the root
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I'm not so sure I like a corner case to be encoded in this function.

Is this issue a special case of capture parameters not being url-decoded first? see #262

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" $ param "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
Loading