| 1 |
commit cc39c313c5eeedf8bc1693e0d80a510891a7fc4d
|
| 2 |
Author: John MacFarlane <jgm@berkeley.edu>
|
| 3 |
Date: Fri Jun 22 21:24:02 2012 +0200
|
| 4 |
|
| 5 |
Don't encode/decode file paths if base >= 4.5.
|
| 6 |
|
| 7 |
Prior to base 4.5 (and perhaps earlier - check), filepaths and command
|
| 8 |
line arguments were treated as unencoded lists of bytes, not unicode
|
| 9 |
strings, so we had to work around that by encoding and decoding
|
| 10 |
them. This commit adds CPP checks for base 4.5 that disable the
|
| 11 |
encoding/decoding.
|
| 12 |
|
| 13 |
Fixes a bug with multilingual filenames when pandoc was compiled
|
| 14 |
with ghc 7.4. Closes #540.
|
| 15 |
|
| 16 |
Upstream-bug: https://github.com/jgm/pandoc/issues/540
|
| 17 |
Reported-by: Nikolaj Sjujskij <sterkrig@myopera.com>
|
| 18 |
diff --git a/src/Text/Pandoc/UTF8.hs b/src/Text/Pandoc/UTF8.hs
|
| 19 |
index 4af1558..929bc3f 100644
|
| 20 |
--- a/src/Text/Pandoc/UTF8.hs
|
| 21 |
+++ b/src/Text/Pandoc/UTF8.hs
|
| 22 |
@@ -39,21 +39,25 @@ module Text.Pandoc.UTF8 ( readFile
|
| 23 |
|
| 24 |
where
|
| 25 |
|
| 26 |
+#if MIN_VERSION_base(4,5,0)
|
| 27 |
+#else
|
| 28 |
+import Codec.Binary.UTF8.String (encodeString)
|
| 29 |
+#endif
|
| 30 |
+
|
| 31 |
#if MIN_VERSION_base(4,2,0)
|
| 32 |
|
| 33 |
import System.IO hiding (readFile, writeFile, getContents,
|
| 34 |
putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
|
| 35 |
import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
|
| 36 |
-import Codec.Binary.UTF8.String (encodeString)
|
| 37 |
import qualified System.IO as IO
|
| 38 |
|
| 39 |
readFile :: FilePath -> IO String
|
| 40 |
readFile f = do
|
| 41 |
- h <- openFile (encodeString f) ReadMode
|
| 42 |
+ h <- openFile (encodePath f) ReadMode
|
| 43 |
hGetContents h
|
| 44 |
|
| 45 |
writeFile :: FilePath -> String -> IO ()
|
| 46 |
-writeFile f s = withFile (encodeString f) WriteMode $ \h -> hPutStr h s
|
| 47 |
+writeFile f s = withFile (encodePath f) WriteMode $ \h -> hPutStr h s
|
| 48 |
|
| 49 |
getContents :: IO String
|
| 50 |
getContents = hGetContents stdin
|
| 51 |
@@ -76,7 +80,6 @@ hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
|
| 52 |
#else
|
| 53 |
|
| 54 |
import qualified Data.ByteString as B
|
| 55 |
-import Codec.Binary.UTF8.String (encodeString)
|
| 56 |
import Data.ByteString.UTF8 (toString, fromString)
|
| 57 |
import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
|
| 58 |
import System.IO (Handle)
|
| 59 |
@@ -91,10 +94,10 @@ stripBOM s | bom `B.isPrefixOf` s = B.drop 3 s
|
| 60 |
stripBOM s = s
|
| 61 |
|
| 62 |
readFile :: FilePath -> IO String
|
| 63 |
-readFile = liftM (toString . stripBOM) . B.readFile . encodeString
|
| 64 |
+readFile = liftM (toString . stripBOM) . B.readFile . encodePath
|
| 65 |
|
| 66 |
writeFile :: FilePath -> String -> IO ()
|
| 67 |
-writeFile f = B.writeFile (encodeString f) . fromString
|
| 68 |
+writeFile f = B.writeFile (encodePath f) . fromString
|
| 69 |
|
| 70 |
getContents :: IO String
|
| 71 |
getContents = liftM (toString . stripBOM) B.getContents
|
| 72 |
@@ -115,3 +118,10 @@ hPutStrLn :: Handle -> String -> IO ()
|
| 73 |
hPutStrLn h s = hPutStr h (s ++ "\n")
|
| 74 |
|
| 75 |
#endif
|
| 76 |
+
|
| 77 |
+encodePath :: FilePath -> FilePath
|
| 78 |
+#if MIN_VERSION_base(4,5,0)
|
| 79 |
+encodePath = id
|
| 80 |
+#else
|
| 81 |
+encodePath = encodeString
|
| 82 |
+#endif
|
| 83 |
diff --git a/src/pandoc.hs b/src/pandoc.hs
|
| 84 |
index 34d136a..7e9646c 100644
|
| 85 |
--- a/src/pandoc.hs
|
| 86 |
+++ b/src/pandoc.hs
|
| 87 |
@@ -1,3 +1,4 @@
|
| 88 |
+{-# LANGUAGE CPP #-}
|
| 89 |
{-
|
| 90 |
Copyright (C) 2006-2012 John MacFarlane <jgm@berkeley.edu>
|
| 91 |
|
| 92 |
@@ -56,8 +57,21 @@ import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
|
| 93 |
import Network.URI (parseURI, isURI, URI(..))
|
| 94 |
import qualified Data.ByteString.Lazy as B
|
| 95 |
import Data.ByteString.Lazy.UTF8 (toString )
|
| 96 |
-import Codec.Binary.UTF8.String (decodeString, encodeString)
|
| 97 |
import Text.CSL.Reference (Reference(..))
|
| 98 |
+#if MIN_VERSION_base(4,5,0)
|
| 99 |
+#else
|
| 100 |
+import Codec.Binary.UTF8.String (decodeString, encodeString)
|
| 101 |
+#endif
|
| 102 |
+
|
| 103 |
+encodePath, decodeArg :: FilePath -> FilePath
|
| 104 |
+#if MIN_VERSION_base(4,5,0)
|
| 105 |
+encodePath = id
|
| 106 |
+decodeArg = id
|
| 107 |
+#else
|
| 108 |
+encodePath = encodeString
|
| 109 |
+decodeArg = decodeString
|
| 110 |
+#endif
|
| 111 |
+
|
| 112 |
|
| 113 |
copyrightMessage :: String
|
| 114 |
copyrightMessage = "\nCopyright (C) 2006-2012 John MacFarlane\n" ++
|
| 115 |
@@ -745,7 +759,7 @@ defaultWriterName x =
|
| 116 |
main :: IO ()
|
| 117 |
main = do
|
| 118 |
|
| 119 |
- rawArgs <- liftM (map decodeString) getArgs
|
| 120 |
+ rawArgs <- liftM (map decodeArg) getArgs
|
| 121 |
prg <- getProgName
|
| 122 |
let compatMode = (prg == "hsmarkdown")
|
| 123 |
|
| 124 |
@@ -1023,7 +1037,7 @@ main = do
|
| 125 |
else return doc1
|
| 126 |
|
| 127 |
let writeBinary :: B.ByteString -> IO ()
|
| 128 |
- writeBinary = B.writeFile (encodeString outputFile)
|
| 129 |
+ writeBinary = B.writeFile (encodePath outputFile)
|
| 130 |
|
| 131 |
let writerFn :: FilePath -> String -> IO ()
|
| 132 |
writerFn "-" = UTF8.putStr
|