From e2a452ba4a47efd1be7cc7d6f2493c4ddbc5a2b0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 27 Nov 2016 21:19:26 +0100 Subject: Shared.fetchItem: Better handling of protocol-relative URL. If URL starts with `//` and there is no "base URL" (as there would be if a URL were used on the command line), then default to http:. Closes #2635. --- src/Text/Pandoc/Shared.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index f06f5f1c7..bd2da945e 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -925,6 +925,10 @@ fetchItem sourceURL s = case parseURIReference' s' of Just u' -> openURL $ show $ u' `nonStrictRelativeTo` u Nothing -> openURL s' -- will throw error + (Nothing, s'@('/':'/':_)) -> -- protocol-relative URI + case parseURIReference' s' of + Just u' -> openURL $ show $ u' `nonStrictRelativeTo` httpcolon + Nothing -> openURL s' -- will throw error (Nothing, s') -> case parseURI s' of -- requires absolute URI -- We don't want to treat C:/ as a scheme: @@ -935,6 +939,11 @@ fetchItem sourceURL s = where readLocalFile f = do cont <- BS.readFile f return (cont, mime) + httpcolon = URI{ uriScheme = "http:", + uriAuthority = Nothing, + uriPath = "", + uriQuery = "", + uriFragment = "" } dropFragmentAndQuery = takeWhile (\c -> c /= '?' && c /= '#') fp = unEscapeString $ dropFragmentAndQuery s mime = case takeExtension fp of -- cgit v1.2.3