From fc4a86bb58ba36c5302591adc78148d2a35ad57a Mon Sep 17 00:00:00 2001 From: Daniel Gnoutcheff Date: Tue, 21 Sep 2021 19:33:29 -0400 Subject: Force utf8 Don't crash on unicode input, even if the environment doesn't contain LANG=en_US.utf8 or the like. --- app/Main.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'app') 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 [] = [] -- cgit v1.2.3