aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-01-08 19:10:46 -0800
committerJohn MacFarlane <[email protected]>2022-01-08 19:10:46 -0800
commita6741bd55525718b4e2eacd17ace07eb2646de08 (patch)
tree8bc60dcfb5fbb7d8ea76b51145255f1546abaad0
parent2b51f54e19373381df7f71f3094f97cc79dd82d2 (diff)
writeMedia: unescape percent-encoding in creating file path.
Closes #7819 (problem with spaces in image filenames when creating PDFs).
-rw-r--r--src/Text/Pandoc/Class/IO.hs4
1 files changed, 3 insertions, 1 deletions
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