[commit: haddock] master: Always read in prologue files as UTF8 (#286). (5bcc099)

git at git.haskell.org git at git.haskell.org
Thu Mar 13 21:20:10 UTC 2014


Repository : ssh://git@git.haskell.org/haddock

On branch  : master
Link       : http://git.haskell.org/haddock.git/commitdiff/5bcc09947718bec704ff9561dc193ba3c50a1ccf

>---------------------------------------------------------------

commit 5bcc09947718bec704ff9561dc193ba3c50a1ccf
Author: Mateusz Kowalczyk <fuuzetsu at fuuzetsu.co.uk>
Date:   Thu Mar 13 21:19:07 2014 +0000

    Always read in prologue files as UTF8 (#286).


>---------------------------------------------------------------

5bcc09947718bec704ff9561dc193ba3c50a1ccf
 CHANGES        |    4 ++++
 src/Haddock.hs |   14 +++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/CHANGES b/CHANGES
index a98a0e0..c59051a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+Changes in version 2.15.0
+
+ * Always read in prologue files as UTF8 (#286 and Cabal #1721)
+
 Changes in version 2.14.1
 
  * Render * and -> with their UnicodeSyntax equivalents if -U is enabled
diff --git a/src/Haddock.hs b/src/Haddock.hs
index e4c7fdc..67c4536 100644
--- a/src/Haddock.hs
+++ b/src/Haddock.hs
@@ -4,7 +4,8 @@
 -- |
 -- Module      :  Haddock
 -- Copyright   :  (c) Simon Marlow 2003-2006,
---                    David Waern  2006-2010
+--                    David Waern  2006-2010,
+--                    Mateusz Kowalczyk 2014
 -- License     :  BSD-like
 --
 -- Maintainer  :  haddock at projects.haskell.org
@@ -447,10 +448,13 @@ getPrologue dflags flags =
   case [filename | Flag_Prologue filename <- flags ] of
     [] -> return Nothing
     [filename] -> do
-      str <- readFile filename
-      case parseParasMaybe dflags str of
-        Nothing -> throwE $ "failed to parse haddock prologue from file: " ++ filename
-        Just doc -> return (Just doc)
+      withFile filename ReadMode $ \h -> do
+        hSetEncoding h utf8
+        str <- hGetContents h
+        case parseParasMaybe dflags str of
+          Nothing ->
+            throwE $ "failed to parse haddock prologue from file: " ++ filename
+          Just doc -> return (Just doc)
     _otherwise -> throwE "multiple -p/--prologue options"
 
 



More information about the ghc-commits mailing list