git.iko.soy/typeable/pandoc
on master help sign in
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.

commite2a452ba4a47efd1be7cc7d6f2493c4ddbc5a2b0 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 27 Nov 2016, 21:19 (10 years ago) parentea91643
1 file changed+9
src/Text/Pandoc/Shared.hs+9
src/Text/Pandoc/Shared.hs+9
@@ -925,6 +925,10 @@ fetchItem sourceURL s =
925925 case parseURIReference' s' of
926926 Just u' -> openURL $ show $ u' `nonStrictRelativeTo` u
927927 Nothing -> openURL s' -- will throw error
928+ (Nothing, s'@('/':'/':_)) -> -- protocol-relative URI
929+ case parseURIReference' s' of
930+ Just u' -> openURL $ show $ u' `nonStrictRelativeTo` httpcolon
931+ Nothing -> openURL s' -- will throw error
928932 (Nothing, s') ->
929933 case parseURI s' of -- requires absolute URI
930934 -- We don't want to treat C:/ as a scheme:
@@ -935,6 +939,11 @@ fetchItem sourceURL s =
935939 where readLocalFile f = do
936940 cont <- BS.readFile f
937941 return (cont, mime)
942+ httpcolon = URI{ uriScheme = "http:",
943+ uriAuthority = Nothing,
944+ uriPath = "",
945+ uriQuery = "",
946+ uriFragment = "" }
938947 dropFragmentAndQuery = takeWhile (\c -> c /= '?' && c /= '#')
939948 fp = unEscapeString $ dropFragmentAndQuery s
940949 mime = case takeExtension fp of