web-routes-0.24.1: Library for maintaining correctness and composability of URLs within an application.




Conversions between raw pathinfos and decoded path segments.



encodePathInfo :: [String] -> [(String, String)] -> StringSource

Encodes a list of path segments into a valid URL fragment.

This function takes the following three steps:

  • UTF-8 encodes the characters.
  • Performs percent encoding on all unreserved characters, as well as :@=+$,
  • Intercalates with a slash.

For example:

 encodePathInfo [\"foo\", \"bar\", \"baz\"]


 encodePathInfo [\"foo bar\", \"baz\/bin\"]


 encodePathInfo [\"\"]


decodePathInfo :: String -> [String]Source

Performs the inverse operation of encodePathInfo.

In particular, this function:

  • Splits a string at each occurence of a forward slash.
  • Percent-decodes the individual pieces.
  • UTF-8 decodes the resulting data.

This utilizes decodeString from the utf8-string library, and thus all UTF-8 decoding errors are handled as per that library.

In general, you will want to strip the leading slash from a pathinfo before passing it to this function. For example:

 decodePathInfo \"\"


 decodePathInfo \"\/\"