scotty-path-normalizer-0.1.0.0: Redirect to a normalized path

Safe HaskellNone
LanguageHaskell2010

Web.Scotty.PathNormalizer

Contents

Synopsis

Scotty action

addPathNormalizer :: ScottyM () Source #

Adds a Scotty route that matches all non-normalized paths, where the action redirects to the corresponding normalized path.

pathNormalizerAction :: ActionM () Source #

A Scotty action which issues a redirect to the normalized form of the request target, or aborts (with next) if the request target is already a normal path.

Normalization implementation

normalizePath :: Text -> NormalizationResult Text Source #

A path that's already in normal form:

>>> normalizePath "/one/two/three"
AlreadyNormal

A path that contains empty segments:

>>> normalizePath "//one/./two/three/"
Normalized "/one/two/three"

A path that goes "up" a directory:

>>> normalizePath "/one/two/three/../four"
Normalized "/one/two/four"

A path that goes up too far:

>>> normalizePath "/one/../../two/three"
Invalid

The root path is a normalized path:

>>> normalizePath "/"
AlreadyNormal

The empty string is not a valid path (because a path must begin with a slash):

>>> normalizePath ""
Invalid

normalizeSegmentList :: [Text] -> NormalizationResult [Text] Source #

A path that's already in normal form:

>>> normalizeSegmentList ["one", "two", "three"]
AlreadyNormal

A path that contains empty segments:

>>> normalizeSegmentList ["", "one", ".", "two", "three"]
Normalized ["one","two","three"]

A path that goes "up" a directory:

>>> normalizeSegmentList ["one", "two", "three", "..", "four"]
Normalized ["one","two","four"]

A path that goes up too far:

>>> normalizeSegmentList ["one", "..", "..", "two", "three"]
Invalid

The empty string is a normalized path:

>>> normalizeSegmentList []
AlreadyNormal