git.iko.soy/typeable/pandoc
on master help sign in
Normalize Windows paths to account for change in ghc 8.6.
ff0aaa5John MacFarlane
src/Text/Pandoc/App/CommandLineOptions.hs+31−9
@@ -96,7 +96,7 @@ parseOptions options' defaults = do
96
96
97 -- thread option data structure through all supplied option actions
97 -- thread option data structure through all supplied option actions
98 opts <- foldl (>>=) (return defaults) actions
98 opts <- foldl (>>=) (return defaults) actions
99− return (opts{ optInputFiles = args })
99+ return (opts{ optInputFiles = map normalizePath args })
100
100
101latexEngines :: [String]
101latexEngines :: [String]
102latexEngines = ["pdflatex", "lualatex", "xelatex"]
102latexEngines = ["pdflatex", "lualatex", "xelatex"]
@@ -149,13 +149,15 @@ options =
149
149
150 , Option "o" ["output"]
150 , Option "o" ["output"]
151 (ReqArg
151 (ReqArg
152− (\arg opt -> return opt { optOutputFile = Just arg })
152+ (\arg opt -> return opt { optOutputFile =
153+ Just (normalizePath arg) })
153 "FILE")
154 "FILE")
154 "" -- "Name of output file"
155 "" -- "Name of output file"
155
156
156 , Option "" ["data-dir"]
157 , Option "" ["data-dir"]
157 (ReqArg
158 (ReqArg
158− (\arg opt -> return opt { optDataDir = Just arg })
159+ (\arg opt -> return opt { optDataDir =
160+ Just (normalizePath arg) })
159 "DIRECTORY") -- "Directory containing pandoc data files."
161 "DIRECTORY") -- "Directory containing pandoc data files."
160 ""
162 ""
161
163
@@ -188,14 +190,16 @@ options =
188 , Option "F" ["filter"]
190 , Option "F" ["filter"]
189 (ReqArg
191 (ReqArg
190 (\arg opt -> return opt { optFilters =
192 (\arg opt -> return opt { optFilters =
193+ JSONFilter (normalizePath arg) :
191− JSONFilter arg : optFilters opt })
194+ optFilters opt })
192 "PROGRAM")
195 "PROGRAM")
193 "" -- "External JSON filter"
196 "" -- "External JSON filter"
194
197
195 , Option "" ["lua-filter"]
198 , Option "" ["lua-filter"]
196 (ReqArg
199 (ReqArg
197 (\arg opt -> return opt { optFilters =
200 (\arg opt -> return opt { optFilters =
201+ LuaFilter (normalizePath arg) :
198− LuaFilter arg : optFilters opt })
202+ optFilters opt })
199 "SCRIPTPATH")
203 "SCRIPTPATH")
200 "" -- "Lua filter"
204 "" -- "Lua filter"
201
205
@@ -235,7 +239,8 @@ options =
235 , Option "" ["extract-media"]
239 , Option "" ["extract-media"]
236 (ReqArg
240 (ReqArg
237 (\arg opt ->
241 (\arg opt ->
238− return opt { optExtractMedia = Just arg })
242+ return opt { optExtractMedia =
243+ Just (normalizePath arg) })
239 "PATH")
244 "PATH")
240 "" -- "Directory to which to extract embedded media"
245 "" -- "Directory to which to extract embedded media"
241
246
@@ -247,7 +252,7 @@ options =
247 , Option "" ["template"]
252 , Option "" ["template"]
248 (ReqArg
253 (ReqArg
249 (\arg opt ->
254 (\arg opt ->
250− return opt{ optTemplate = Just arg,
255+ return opt{ optTemplate = Just (normalizePath arg),
251 optStandalone = True })
256 optStandalone = True })
252 "FILE")
257 "FILE")
253 "" -- "Use custom template"
258 "" -- "Use custom template"
@@ -262,7 +267,8 @@ options =
262
267
263 , Option "" ["metadata-file"]
268 , Option "" ["metadata-file"]
264 (ReqArg
269 (ReqArg
265− (\arg opt -> return opt{ optMetadataFile = Just arg })
270+ (\arg opt -> return opt{ optMetadataFile =
271+ Just (normalizePath arg) })
266 "FILE")
272 "FILE")
267 ""
273 ""
268
274
@@ -405,7 +411,7 @@ options =
405 -- HXT confuses Windows path with URI
411 -- HXT confuses Windows path with URI
406 _:':':'\\':_ ->
412 _:':':'\\':_ ->
407 "file:///" ++ tr '\\' '/' arg
413 "file:///" ++ tr '\\' '/' arg
408− _ -> arg
414+ _ -> normalizePath arg
409 return opt{ optSyntaxDefinitions = arg' :
415 return opt{ optSyntaxDefinitions = arg' :
410 optSyntaxDefinitions opt })
416 optSyntaxDefinitions opt })
411 "FILE")
417 "FILE")
@@ -931,3 +937,19 @@ deprecatedOption o msg =
931 \r -> case r of
937 \r -> case r of
932 Right () -> return ()
938 Right () -> return ()
933 Left e -> E.throwIO e
939 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