Skip to content

Commit cb821c5

Browse files
committed
Fixed [""] for /route/ on CaptureAll apis.
* Routes ending in a `CaptureAll` now get an empty list instead of [""] when they have a trailing slash. * WARNING: I think this will break the expectation that a rooted capture all will produce [""] for `//`. That is, previously `// => [""]`, but I think `// => []`. I will make some tests to check and see what is going on with this.
1 parent ea96794 commit cb821c5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

servant-server/src/Servant/Server/Internal/Router.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ runRouterEnv fmt router env request respond =
178178
-> let request' = request { pathInfo = rest }
179179
in runRouterEnv fmt router' (first, env) request' respond
180180
CaptureAllRouter router' ->
181-
let segments = pathInfo request
181+
let segments = case pathInfo request of
182+
-- This case handles empty capture alls in a sub route like:
183+
-- /legs/ => [] instead of [""]
184+
-- But will this break a rooted capture all? like:
185+
-- // => [] instead of [""]
186+
-- Maybe we should fix it in Wai first.
187+
[""] -> []
188+
xs -> xs
182189
request' = request { pathInfo = [] }
183190
in runRouterEnv fmt router' (segments, env) request' respond
184191
RawRouter app ->

servant-server/test/Servant/ServerSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ type CaptureAllApi = "legs" :> CaptureAll "legs" Integer :> Get '[JSON] Animal
273273
captureAllApi :: Proxy CaptureAllApi
274274
captureAllApi = Proxy
275275
captureAllServer :: Server CaptureAllApi
276-
captureAllServer = handleLegs :<|> (return :: [String] -> Handler [String])
276+
captureAllServer = handleLegs :<|> return
277277
where
278278
handleLegs [] = return beholder
279279
handleLegs legs = case sum legs of

0 commit comments

Comments
 (0)