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.
This commit is contained in:
Guy Gastineau 2022-01-25 14:31:36 -05:00
parent ea96794763
commit cb821c5ca0
No known key found for this signature in database
GPG Key ID: BC92DE181D2AF254
2 changed files with 9 additions and 2 deletions

View File

@ -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 ->

View File

@ -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