git.iko.soy/typeable/pandoc
on master help sign in
PDF: don't assume tex log file is UTF8-encoded.

Fall back to latin1 if it can't be read as UTF-8. Closes #5872.

commitfdc0f47519d330bcc641eeaee68486431d3c46a5 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 3 Nov 2019, 21:24 (7 years ago) parent11945ea
1 file changed+11−2
src/Text/Pandoc/PDF.hs+11−2
src/Text/Pandoc/PDF.hs+11−2
@@ -27,6 +27,8 @@ import qualified Data.ByteString.Lazy.Char8 as BC
2727import Data.Maybe (fromMaybe)
2828import Data.Text (Text)
2929import qualified Data.Text as T
30+import qualified Data.Text.Lazy as TL
31+import Data.Text.Lazy.Encoding (decodeUtf8')
3032import Text.Printf (printf)
3133import Data.Char (ord, isAscii, isSpace)
3234import System.Directory
@@ -265,7 +267,7 @@ missingCharacterWarnings verbosity log' = do
265267 | isAscii c = c : addCodePoint cs
266268 | otherwise = c : " (U+" ++ printf "%04X" (ord c) ++ ")" ++
267269 addCodePoint cs
268− let warnings = [ addCodePoint (UTF8.toStringLazy (BC.drop 19 l))
270+ let warnings = [ addCodePoint (utf8ToString (BC.drop 19 l))
269271 | l <- ls
270272 , isMissingCharacterWarning l
271273 ]
@@ -308,7 +310,8 @@ runTectonic verbosity program args' tmpDir' source = do
308310 let programArgs = ["--outdir", tmpDir] ++ args ++ ["-"]
309311 env <- liftIO getEnvironment
310312 when (verbosity >= INFO) $ liftIO $
311− showVerboseInfo (Just tmpDir) program programArgs env (UTF8.toStringLazy sourceBL)
313+ showVerboseInfo (Just tmpDir) program programArgs env
314+ (utf8ToString sourceBL)
312315 (exit, out) <- liftIO $ E.catch
313316 (pipeProcess (Just env) program programArgs sourceBL)
314317 (handlePDFProgramNotFound program)
@@ -512,3 +515,9 @@ handlePDFProgramNotFound program e
512515 | IE.isDoesNotExistError e =
513516 E.throwIO $ PandocPDFProgramNotFoundError program
514517 | otherwise = E.throwIO e
518+
519+utf8ToString :: ByteString -> String
520+utf8ToString lbs =
521+ case decodeUtf8' lbs of
522+ Left _ -> BC.unpack lbs -- if decoding fails, treat as latin1
523+ Right t -> TL.unpack t