aboutsummaryrefslogtreecommitdiff
path: root/Utility/Url.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-06-14 13:39:44 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-06-14 13:39:44 -0400
commit42983b9ecb1b02279e83c6922ba165b97bf69a54 (patch)
treea707fa0b55f3f78f82e0cee339c218d899a18844 /Utility/Url.hs
parentfdbe8596c5f5dbe4d59c32c0ed42532ff51e5f45 (diff)
Improve url parsing to handle some urls containing illegal [] characters in their paths.
Ie, "https://archive.org/download/zoom-2/Zoom - Release 2 (1996)(Active Software)[!].iso"
Diffstat (limited to 'Utility/Url.hs')
-rw-r--r--Utility/Url.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/Utility/Url.hs b/Utility/Url.hs
index 81a9a1b05..d8895a918 100644
--- a/Utility/Url.hs
+++ b/Utility/Url.hs
@@ -263,7 +263,17 @@ download' quiet url file uo = do
{- Allows for spaces and other stuff in urls, properly escaping them. -}
parseURIRelaxed :: URLString -> Maybe URI
-parseURIRelaxed = parseURI . escapeURIString isAllowedInURI
+parseURIRelaxed s = maybe (go escapemore) Just $ go isAllowedInURI
+ where
+ go f = parseURI $ escapeURIString f s
+ {- Some characters like '[' are allowed in eg, the address of
+ - an uri, but cannot appear unescaped elsewhere in the uri.
+ - If parsing fails with those characters unescaped, fall back
+ - to escaping them too.
+ -}
+ escapemore '[' = False
+ escapemore ']' = False
+ escapemore c = isAllowedInURI c
hAcceptEncoding :: CI.CI B.ByteString
hAcceptEncoding = "Accept-Encoding"