aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Class.hs4
-rw-r--r--test/command/5517.md26
2 files changed, 28 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index fb3cfa72a..8d9caa6e8 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -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
diff --git a/test/command/5517.md b/test/command/5517.md
new file mode 100644
index 000000000..e309d84a4
--- /dev/null
+++ b/test/command/5517.md
@@ -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
+```