diff --git a/servant-server/src/Servant/Server/Internal/Router.hs b/servant-server/src/Servant/Server/Internal/Router.hs index ecee5901..e5623ffb 100644 --- a/servant-server/src/Servant/Server/Internal/Router.hs +++ b/servant-server/src/Servant/Server/Internal/Router.hs @@ -178,7 +178,14 @@ runRouterEnv fmt router env request respond = -> let request' = request { pathInfo = rest } in runRouterEnv fmt router' (first, env) request' respond CaptureAllRouter router' -> - let segments = pathInfo request + let segments = case pathInfo request of + -- This case handles empty capture alls in a sub route like: + -- /legs/ => [] instead of [""] + -- But will this break a rooted capture all? like: + -- // => [] instead of [""] + -- Maybe we should fix it in Wai first. + [""] -> [] + xs -> xs request' = request { pathInfo = [] } in runRouterEnv fmt router' (segments, env) request' respond RawRouter app -> diff --git a/servant-server/test/Servant/ServerSpec.hs b/servant-server/test/Servant/ServerSpec.hs index 401abcf3..cc502e8c 100644 --- a/servant-server/test/Servant/ServerSpec.hs +++ b/servant-server/test/Servant/ServerSpec.hs @@ -273,7 +273,7 @@ type CaptureAllApi = "legs" :> CaptureAll "legs" Integer :> Get '[JSON] Animal captureAllApi :: Proxy CaptureAllApi captureAllApi = Proxy captureAllServer :: Server CaptureAllApi -captureAllServer = handleLegs :<|> (return :: [String] -> Handler [String]) +captureAllServer = handleLegs :<|> return where handleLegs [] = return beholder handleLegs legs = case sum legs of