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.
This commit is contained in:
parent
ea916432ac
commit
e2a452ba4a
1 changed files with 9 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue