Skip to content

Commit

Permalink
Shared.openURL: URL-escape pipe characters.
Browse files Browse the repository at this point in the history
Even though these are legal, Network.URI doesn't regard them
as legal in URLs.  So we escape them first.

Closes jgm#535.
  • Loading branch information
jgm committed Apr 29, 2013
1 parent 4edc97a commit 1991edf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Text/Pandoc/Shared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,16 @@ fetchItem sourceDir s =
cont <- B.readFile f
return (cont, mime)

-- TODO - have this return mime type too - then it can work for google
-- chart API, e.g.
-- | Read from a URL and return raw data and maybe mime type.
openURL :: String -> IO (B.ByteString, Maybe String)
openURL u = getBodyAndMimeType `fmap`
browse (setAllowRedirects True >> request (getRequest' u))
browse (setAllowRedirects True >> request (getRequest' u'))
where getBodyAndMimeType (_, r) = (rspBody r, findHeader HdrContentType r)
getRequest' uriString = case parseURI uriString of
Nothing -> error ("Not a valid URL: " ++
uriString)
Just v -> mkRequest GET v
u' = escapeURIString (/= '|') u -- pipes are rejected by Network.URI

--
-- Error reporting
Expand Down

0 comments on commit 1991edf

Please sign in to comment.