More intelligent cleanPath
This commit is contained in:
parent
fecdd6e744
commit
37c261fa1e
@ -179,9 +179,9 @@ class RenderRoute (Route a) => Yesod a where
|
|||||||
authRoute :: a -> Maybe (Route a)
|
authRoute :: a -> Maybe (Route a)
|
||||||
authRoute _ = Nothing
|
authRoute _ = Nothing
|
||||||
|
|
||||||
-- | A function used to clean up path segments. It returns 'Nothing' when
|
-- | A function used to clean up path segments. It returns 'Right' with a
|
||||||
-- the given path is already clean, and a 'Just' when Yesod should redirect
|
-- clean path or 'Left' with a new set of pieces the user should be
|
||||||
-- to the given path pieces.
|
-- redirected to. The default implementation enforces:
|
||||||
--
|
--
|
||||||
-- * No double slashes
|
-- * No double slashes
|
||||||
--
|
--
|
||||||
@ -189,11 +189,11 @@ class RenderRoute (Route a) => Yesod a where
|
|||||||
--
|
--
|
||||||
-- Note that versions of Yesod prior to 0.7 used a different set of rules
|
-- Note that versions of Yesod prior to 0.7 used a different set of rules
|
||||||
-- involing trailing slashes.
|
-- involing trailing slashes.
|
||||||
cleanPath :: a -> [String] -> Maybe [String]
|
cleanPath :: a -> [String] -> Either [String] [String]
|
||||||
cleanPath _ s =
|
cleanPath _ s =
|
||||||
if corrected == s
|
if corrected == s
|
||||||
then Nothing
|
then Right s
|
||||||
else Just corrected
|
else Left corrected
|
||||||
where
|
where
|
||||||
corrected = filter (not . null) s
|
corrected = filter (not . null) s
|
||||||
|
|
||||||
|
|||||||
@ -189,11 +189,11 @@ toWaiApp' y key' env = do
|
|||||||
Just app -> app env
|
Just app -> app env
|
||||||
Nothing ->
|
Nothing ->
|
||||||
case cleanPath y segments of
|
case cleanPath y segments of
|
||||||
Nothing ->
|
Right segments' ->
|
||||||
case yesodDispatch y key' segments y id of
|
case yesodDispatch y key' segments' y id of
|
||||||
Just app -> app env
|
Just app -> app env
|
||||||
Nothing -> yesodRunner y y id key' Nothing notFound env
|
Nothing -> yesodRunner y y id key' Nothing notFound env
|
||||||
Just segments' ->
|
Left segments' ->
|
||||||
let dest = joinPath y (approot y) segments' []
|
let dest = joinPath y (approot y) segments' []
|
||||||
dest' =
|
dest' =
|
||||||
if S.null (W.queryString env)
|
if S.null (W.queryString env)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user