From a6741bd55525718b4e2eacd17ace07eb2646de08 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 8 Jan 2022 19:10:46 -0800 Subject: [PATCH] writeMedia: unescape percent-encoding in creating file path. Closes #7819 (problem with spaces in image filenames when creating PDFs). --- src/Text/Pandoc/Class/IO.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Class/IO.hs b/src/Text/Pandoc/Class/IO.hs index 305f07a01..5d4dbc715 100644 --- a/src/Text/Pandoc/Class/IO.hs +++ b/src/Text/Pandoc/Class/IO.hs @@ -214,13 +214,15 @@ extractMedia dir d = do return $ walk (adjustImagePath dir media) d -- | Write the contents of a media bag to a path. +-- If the path contains URI escape sequences (percent-encoding), +-- these are resolved. writeMedia :: (PandocMonad m, MonadIO m) => FilePath -> (FilePath, MimeType, BL.ByteString) -> m () writeMedia dir (fp, _mt, bs) = do -- we normalize to get proper path separators for the platform - let fullpath = normalise $ dir fp + let fullpath = normalise $ dir unEscapeString fp liftIOError (createDirectoryIfMissing True) (takeDirectory fullpath) logIOError $ BL.writeFile fullpath bs