I'd like to url-encode some Text (e.g., replace each space with a %20, etc.). I found "HTTP" Network.HTTP.Base.urlEncode and could use that, but I'm wondering if there's something else that's normally used in the Yesod ecosystem.
Asked
Active
Viewed 830 times
6
-
After some hunting, I found that "http-conduit" Network.HTTP.Conduit.parseUrl uses (escapeURIString isAllowedInURI) from "network" Network.URI. Is this what other Yesod'ers use? – Tad Dec 19 '13 at 07:11
-
Grep'ing through the code, I found that joinPath in Yesod.hs uses Network.HTTP.Types.encodePath/encodePathSegments to create paths, which does the percent escaping, amongst other things.... This is for creating percent escaped urls from a parsed path object though (not from Text). – jamshidh Dec 19 '13 at 07:17
1 Answers
6
Unfortunately, due to the complexity of URL escaping, the real answer is "it depends." There are slightly different rules for the percent encoding of path segments and query strings, for example.
I don't know exactly what you're trying to encode, but I'd recommend sticking to the http-types package. One place to start would be urlEncode, though there are many other functions in that packages (such as encodePathSegments
mentioned by @jamshidh) which are worth looking at.

lehins
- 9,642
- 2
- 35
- 49

Michael Snoyman
- 31,100
- 3
- 48
- 77
-
-
For more info: http://stackoverflow.com/questions/33704839/discrepancies-of-percent-encoding-for-urls – Athan Clark Nov 14 '15 at 05:16