Fix handling of file: URL scheme in downloadOrRead (#5522)

Move up the pattern match to be reachable, closes #5517.

Previously `file:/` URLs were handled wrongly and pandoc attempted
to make HTTP requests, which failed.
This commit is contained in:
Mauro Bieg 2019-05-28 17:51:21 +02:00 committed by John MacFarlane
parent 0be83f24a9
commit 214da7217b
2 changed files with 28 additions and 2 deletions

View file

@ -572,10 +572,10 @@ downloadOrRead s = do
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:
Just u' | length (uriScheme u') > 2 -> openURL (show u')
Just u' | uriScheme u' == "file:" ->
readLocalFile $ uriPathToPath (uriPath u')
-- We don't want to treat C:/ as a scheme:
Just u' | length (uriScheme u') > 2 -> openURL (show u')
_ -> readLocalFile fp -- get from local file system
where readLocalFile f = do
resourcePath <- getResourcePath

26
test/command/5517.md Normal file
View file

@ -0,0 +1,26 @@
Use epub output to trigger `downloadOrRead` in `Text.Pandoc.Class`
in order to test `file:` URL-scheme handling.
There are no relative `file:` URLs, so we cannot
test with an actual file, since we don't know the
current working directory. Instead, we use `/dev/null`
as a file that certainly exists, redirect stderr
to stdout and check that there is no warning.
```
% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
[Para [Image ("",[],[]) [] ("file:/dev/null","")]]
^D
```
```
% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
[Para [Image ("",[],[]) [] ("file:///dev/null","")]]
^D
```
```
% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
[Para [Image ("",[],[]) [] ("file://localhost/dev/null","")]]
^D
```