Skip to content

Commit

Permalink
Merge pull request #451 from ethereum/fix-foundry-stuff
Browse files Browse the repository at this point in the history
Fix foundry JSON reading that was dependent on locale
  • Loading branch information
msooseth authored Feb 16, 2024
2 parents 5584187 + f749904 commit 9dc261e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Traces now correctly perform source mapping to display contract details
- Event traces now correctly display indexed arguments and argument names
- JSON reading of foundry JSONs was dependent on locale and did not work with many locales.

## [0.52.0] - 2023-10-26

Expand Down
11 changes: 7 additions & 4 deletions src/EVM/Solidity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import Data.Aeson.Optics
import Data.Aeson.Key qualified as Key
import Data.Aeson.KeyMap qualified as KeyMap
import Data.Scientific
import Data.ByteString (ByteString)
import Data.ByteString (ByteString, readFile)
import Data.ByteString qualified as BS
import Data.ByteString.Base16 qualified as BS16
import Data.ByteString.Lazy (toStrict)
Expand All @@ -73,7 +73,6 @@ import Data.Sequence (Seq)
import Data.Text (pack, intercalate)
import Data.Text qualified as T
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
import Data.Text.IO (readFile)
import Data.Vector (Vector)
import Data.Vector qualified as Vector
import Data.Word (Word8)
Expand Down Expand Up @@ -344,8 +343,12 @@ lineSubrange xs (s1, n1) i =
else Just (s1 - s2, min (s2 + n2 - s1) n1)

readSolc :: ProjectType -> FilePath -> FilePath -> IO (Either String BuildOutput)
readSolc pt root fp =
(readJSON pt (T.pack $ takeBaseName fp) <$> readFile fp) >>=
readSolc pt root fp = do
-- NOTE: we cannot and must not use Data.Text.IO.readFile because that takes the locale
-- and may fail with very strange errors when the JSON it's reading
-- contains any UTF-8 character -- which it will with foundry
let fileContents = fmap Data.Text.Encoding.decodeUtf8 (Data.ByteString.readFile fp)
(readJSON pt (T.pack $ takeBaseName fp) <$> fileContents) >>=
\case
Nothing -> pure . Left $ "unable to parse: " <> fp
Just (contracts, asts, sources) -> do
Expand Down

0 comments on commit 9dc261e

Please sign in to comment.