aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-05-08 09:54:19 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-05-08 09:56:42 -0700
commit3a291dad3534b6936731b54276b185214a1d6298 (patch)
tree5be0c55db6ebca69859e3752bae21e4fb9b677d2
parenteb3521e4c9ae044f170433d4e30570a0d0578e20 (diff)
downloadpandoc-3a291dad3534b6936731b54276b185214a1d6298.tar.gz
Shared: add uriPathToPath.
This adjusts the path from a file: URI in a way that is sensitive to Windows/Linux differences. Thus, on Windows, `/c:/foo` gets interpreted as `c:/foo`, but on Linux, `/c:/foo` gets interpreted as `/c:/foo`. See #4613.
-rw-r--r--src/Text/Pandoc/Shared.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 8b1af19cd..82ac32980 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -84,6 +84,7 @@ module Text.Pandoc.Shared (
-- * File handling
inDirectory,
collapseFilePath,
+ uriPathToPath,
filteredFilesFromArchive,
-- * URI handling
schemes,
@@ -635,6 +636,19 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
isSingleton _ = Nothing
checkPathSeperator = fmap isPathSeparator . isSingleton
+-- Convert the path part of a file: URI to a regular path.
+-- On windows, @/c:/foo@ should be @c:/foo@.
+-- On linux, @/foo@ should be @/foo@.
+uriPathToPath :: String -> FilePath
+uriPathToPath path =
+#ifdef _WINDOWS
+ case path of
+ '/':ps -> ps
+ _ -> p
+#else
+ path
+#endif
+
--
-- File selection from the archive
--