Skip to content

Commit

Permalink
fix handling of file: URL scheme in downloadOrRead
Browse files Browse the repository at this point in the history
move up the pattern match to be reachable, closes jgm#5517
  • Loading branch information
mb21 committed May 24, 2019
1 parent 20144a2 commit 5df7359
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Text/Pandoc/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/command/5517.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 redirect
stderr to stdout and check for the correct warning.

```
% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
[Para [Image ("",[],[]) [] ("file:/testpath/foo.jpg","")]]
^D
[WARNING] Could not fetch resource 'file:/testpath/foo.jpg': PandocIOError "/testpath/foo.jpg" /testpath/foo.jpg: openBinaryFile: does not exist (No such file or directory)
```

```
% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
[Para [Image ("",[],[]) [] ("file:///testpath/foo.jpg","")]]
^D
[WARNING] Could not fetch resource 'file:///testpath/foo.jpg': PandocIOError "/testpath/foo.jpg" /testpath/foo.jpg: openBinaryFile: does not exist (No such file or directory)
```

```
% pandoc -M title=test -f native -t epub -o /dev/null 2>&1
[Para [Image ("",[],[]) [] ("file://localhost/testpath/foo.jpg","")]]
^D
[WARNING] Could not fetch resource 'file://localhost/testpath/foo.jpg': PandocIOError "/testpath/foo.jpg" /testpath/foo.jpg: openBinaryFile: does not exist (No such file or directory)
```

0 comments on commit 5df7359

Please sign in to comment.