diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-11-27 21:19:26 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-11-27 21:19:26 +0100 |
commit | e2a452ba4a47efd1be7cc7d6f2493c4ddbc5a2b0 (patch) | |
tree | 5e8a8ae3a1d50de76b8e86bdaa9a9d0672258804 | |
parent | ea916432acea8a2db02b1ba3a7647635684e3cc1 (diff) | |
download | pandoc-e2a452ba4a47efd1be7cc7d6f2493c4ddbc5a2b0.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 9 |
1 files changed, 9 insertions, 0 deletions
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 |