Skip to content

A peer-to-peer stack for code collaboration

Always read radicle code as UTF-8

Thomas Scholtesf19987df8ccc
diff --git a/exe/RadicleExe.hs b/exe/RadicleExe.hs
index 1568b08..ecf33fd 100644
--- a/exe/RadicleExe.hs
+++ b/exe/RadicleExe.hs
@@ -3,6 +3,7 @@ module RadicleExe (main) where
import Prelude (String)
import Protolude hiding (TypeError, option, sourceFile)
+import qualified Data.ByteString as BS
import Options.Applicative
import System.Directory (doesFileExist)
@@ -17,7 +18,7 @@ main = do
code <-
if sourceFile opts' == "-"
then do
- src <- getContents
+ src <- decodeUtf8With lenientDecode <$> BS.getContents
let prog = interpretMany "[stdin]" src
bindings <- createBindings (toS <$> scriptArgs opts')
(result, _state) <- runLang bindings prog
@@ -45,10 +46,10 @@ main = do
readSource :: String -> IO Text
readSource file = do
- exists <- doesFileExist file
- if exists
- then readFile file
- else die $ "Could not find file: " <> toS file
+ exists <- doesFileExist file
+ if exists
+ then decodeUtf8With lenientDecode <$> BS.readFile file
+ else die $ "Could not find file: " <> toS file
radDesc :: String
radDesc
diff --git a/package.yaml b/package.yaml
index 6351fd0..44d4d4d 100644
--- a/package.yaml
+++ b/package.yaml
@@ -89,6 +89,7 @@ executables:
other-modules: []
dependencies:
- radicle
+ - bytestring
- directory
- optparse-applicative
when:
diff --git a/src/Radicle/Internal/Effects/Capabilities.hs b/src/Radicle/Internal/Effects/Capabilities.hs
index 42574d7..0de02bf 100644
--- a/src/Radicle/Internal/Effects/Capabilities.hs
+++ b/src/Radicle/Internal/Effects/Capabilities.hs
@@ -7,6 +7,7 @@ module Radicle.Internal.Effects.Capabilities where
import Protolude
+import qualified Data.ByteString as BS
import Data.Text.Prettyprint.Doc (PageWidth)
import Data.Time
import System.Console.ANSI (hSupportsANSI)
@@ -149,7 +150,7 @@ instance ReadFile (InputT IO) where
instance ReadFile (InputT IO) where
readFileS = lift . readFileS
instance ReadFile IO where
- readFileS fname = (Right <$> readFile (toS fname))
+ readFileS fname = (Right . decodeUtf8With lenientDecode <$> BS.readFile (toS fname))
`catch` (\(e :: IOException) -> pure (Left (show e)))
#endif
instance {-# OVERLAPPABLE #-} ReadFile m => ReadFile (Lang m) where