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

commit214da7217bfc86d0bbe7c0175d2e2e97a00313a5 authorMauro Bieg <mb21@users.noreply.github.com> dateTue 28 May 2019, 17:51 (7 years ago) parent0be83f2
2 files changed+28−2
src/Text/Pandoc/Class.hs+2−2 test/command/5517.md+26
src/Text/Pandoc/Class.hs+2−2
@@ -572,10 +572,10 @@ downloadOrRead s = do
572572 Nothing -> openURL s' -- will throw error
573573 (Nothing, s') ->
574574 case parseURI s' of -- requires absolute URI
575− -- We don't want to treat C:/ as a scheme:
576− Just u' | length (uriScheme u') > 2 -> openURL (show u')
577575 Just u' | uriScheme u' == "file:" ->
578576 readLocalFile $ uriPathToPath (uriPath u')
577+ -- We don't want to treat C:/ as a scheme:
578+ Just u' | length (uriScheme u') > 2 -> openURL (show u')
579579 _ -> readLocalFile fp -- get from local file system
580580 where readLocalFile f = do
581581 resourcePath <- getResourcePath
test/command/5517.mdnew file+26
@@ -0,0 +1,26 @@
1+Use epub output to trigger `downloadOrRead` in `Text.Pandoc.Class`
2+in order to test `file:` URL-scheme handling.
3+
4+There are no relative `file:` URLs, so we cannot
5+test with an actual file, since we don't know the
6+current working directory. Instead, we use `/dev/null`
7+as a file that certainly exists, redirect stderr
8+to stdout and check that there is no warning.
9+
10+```
11+% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
12+[Para [Image ("",[],[]) [] ("file:/dev/null","")]]
13+^D
14+```
15+
16+```
17+% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
18+[Para [Image ("",[],[]) [] ("file:///dev/null","")]]
19+^D
20+```
21+
22+```
23+% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
24+[Para [Image ("",[],[]) [] ("file://localhost/dev/null","")]]
25+^D
26+```