git.iko.soy/typeable/pandoc
on master help sign in
Normalize Windows paths to account for change in ghc 8.6.

When pandoc is compiled with ghc 8.6, Windows paths are treated differently, and paths beginning `\\server` no longer work. This commit rewrites such patsh to `\\?\UNC\server` which works. The change operates at the level of argument parsing, so it only affects the command line program. See #5127 and the discussion there.

commitff0aaa549d51384ef3cdcb063706dee4f6143444 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 26 Jan 2019, 16:07 (8 years ago) parent446583e
1 file changed+31−9
src/Text/Pandoc/App/CommandLineOptions.hs+31−9
src/Text/Pandoc/App/CommandLineOptions.hs+31−9
@@ -96,7 +96,7 @@ parseOptions options' defaults = do
9696
9797 -- thread option data structure through all supplied option actions
9898 opts <- foldl (>>=) (return defaults) actions
99− return (opts{ optInputFiles = args })
99+ return (opts{ optInputFiles = map normalizePath args })
100100
101101latexEngines :: [String]
102102latexEngines = ["pdflatex", "lualatex", "xelatex"]
@@ -149,13 +149,15 @@ options =
149149
150150 , Option "o" ["output"]
151151 (ReqArg
152− (\arg opt -> return opt { optOutputFile = Just arg })
152+ (\arg opt -> return opt { optOutputFile =
153+ Just (normalizePath arg) })
153154 "FILE")
154155 "" -- "Name of output file"
155156
156157 , Option "" ["data-dir"]
157158 (ReqArg
158− (\arg opt -> return opt { optDataDir = Just arg })
159+ (\arg opt -> return opt { optDataDir =
160+ Just (normalizePath arg) })
159161 "DIRECTORY") -- "Directory containing pandoc data files."
160162 ""
161163
@@ -188,14 +190,16 @@ options =
188190 , Option "F" ["filter"]
189191 (ReqArg
190192 (\arg opt -> return opt { optFilters =
191− JSONFilter arg : optFilters opt })
193+ JSONFilter (normalizePath arg) :
194+ optFilters opt })
192195 "PROGRAM")
193196 "" -- "External JSON filter"
194197
195198 , Option "" ["lua-filter"]
196199 (ReqArg
197200 (\arg opt -> return opt { optFilters =
198− LuaFilter arg : optFilters opt })
201+ LuaFilter (normalizePath arg) :
202+ optFilters opt })
199203 "SCRIPTPATH")
200204 "" -- "Lua filter"
201205
@@ -235,7 +239,8 @@ options =
235239 , Option "" ["extract-media"]
236240 (ReqArg
237241 (\arg opt ->
238− return opt { optExtractMedia = Just arg })
242+ return opt { optExtractMedia =
243+ Just (normalizePath arg) })
239244 "PATH")
240245 "" -- "Directory to which to extract embedded media"
241246
@@ -247,7 +252,7 @@ options =
247252 , Option "" ["template"]
248253 (ReqArg
249254 (\arg opt ->
250− return opt{ optTemplate = Just arg,
255+ return opt{ optTemplate = Just (normalizePath arg),
251256 optStandalone = True })
252257 "FILE")
253258 "" -- "Use custom template"
@@ -262,7 +267,8 @@ options =
262267
263268 , Option "" ["metadata-file"]
264269 (ReqArg
265− (\arg opt -> return opt{ optMetadataFile = Just arg })
270+ (\arg opt -> return opt{ optMetadataFile =
271+ Just (normalizePath arg) })
266272 "FILE")
267273 ""
268274
@@ -405,7 +411,7 @@ options =
405411 -- HXT confuses Windows path with URI
406412 _:':':'\\':_ ->
407413 "file:///" ++ tr '\\' '/' arg
408− _ -> arg
414+ _ -> normalizePath arg
409415 return opt{ optSyntaxDefinitions = arg' :
410416 optSyntaxDefinitions opt })
411417 "FILE")
@@ -931,3 +937,19 @@ deprecatedOption o msg =
931937 \r -> case r of
932938 Right () -> return ()
933939 Left e -> E.throwIO e
940+
941+-- On Windows with ghc 8.6+, we need to rewrite paths
942+-- beginning with \\ to \\?\UNC\. -- See #5127.
943+normalizePath :: FilePath -> FilePath
944+#ifdef _WINDOWS
945+#if MIN_VERSION_base(4,12,0)
946+normalizePath fp =
947+ if "\\\\" `isPrefixOf` fp && not ("\\\\?\\" `isPrefixOf` fp)
948+ then "\\\\?\\UNC\\" ++ drop 2 fp
949+ else fp
950+#else
951+normalizePath = id
952+#endif
953+#else
954+normalizePath = id
955+#endif