From 3a291dad3534b6936731b54276b185214a1d6298 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 09:54:19 -0700 Subject: 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. --- src/Text/Pandoc/Shared.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Text/Pandoc') 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 -- -- cgit v1.2.3