summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-21 19:33:29 -0400
committerDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-21 19:33:29 -0400
commitfc4a86bb58ba36c5302591adc78148d2a35ad57a (patch)
tree720bc62641da62329256f6138816ccd3216b6616
parent07284b39f90bd85d19d12e0880c1e2f215d1eb0c (diff)
Force utf8
Don't crash on unicode input, even if the environment doesn't contain LANG=en_US.utf8 or the like.
-rw-r--r--app/Main.hs7
1 files changed, 5 insertions, 2 deletions
diff --git a/app/Main.hs b/app/Main.hs
index ae8bece..6a416be 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -13,7 +13,7 @@ module Main (main) where
import XMLParse -- Our slightly modified copy of Text.XML.HaXml.Parse
-import System.IO (hFlush, stdout)
+import System.IO (stdin, stdout, hSetEncoding, utf8, hFlush)
import Text.XML.HaXml.Lex (xmlLex)
import Text.XML.HaXml.Posn (Posn ())
import Text.ParserCombinators.Poly.State (stGet)
@@ -47,7 +47,10 @@ bslOut :: [BSL.ByteString] -> IO ()
bslOut = mapM_ $ (*> hFlush stdout) . BSL8.putStrLn
main :: IO ()
-main = bslOut . plugin =<< rpcIn
+main = do
+ hSetEncoding stdin utf8
+ hSetEncoding stdout utf8
+ bslOut . plugin =<< rpcIn
plugin :: [Document Posn] -> [BSL.ByteString]
plugin [] = []