Skip to content

Commit

Permalink
Merge pull request #952 from korayal/do-not-log-nonprintable-bytestrings
Browse files Browse the repository at this point in the history
Use `decodeUtf8'` to check whether bytestrings are printable before logging
  • Loading branch information
endgame committed Aug 7, 2023
2 parents e081929 + b65ee45 commit 7353924
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/amazonka-core/src/Amazonka/Data/Log.hs
Expand Up @@ -17,6 +17,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Builder as Build
import qualified Data.ByteString.Lazy as LBS
import qualified Data.CaseInsensitive as CI
import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
Expand All @@ -34,10 +35,14 @@ instance ToLog ByteStringBuilder where
build = id

instance ToLog ByteStringLazy where
build = Build.lazyByteString
build lbs = case LText.decodeUtf8' lbs of
Right lt | LText.all Char.isPrint lt -> Build.lazyByteString lbs
_ -> mconcat ["non-printable lazy ByteString (", build (LBS.length lbs), " bytes)"]

instance ToLog ByteString where
build = Build.byteString
build bs = case Text.decodeUtf8' bs of
Right t | Text.all Char.isPrint t -> Build.byteString bs
_ -> mconcat ["non-printable strict ByteString (", build (BS.length bs), " bytes)"]

instance ToLog Int where
build = Build.intDec
Expand Down
5 changes: 5 additions & 0 deletions lib/amazonka/CHANGELOG.md
@@ -1,5 +1,10 @@
# Change Log

## Unreleased

- `amazonka`: During logging, do not print bytestrings that have unprintable characters
[\#952](https://github.com/brendanhay/amazonka/pull/952)

## [2.0.0](https://github.com/brendanhay/amazonka/tree/2.0.0)
Released: **28 July 2023**, Compare: [2.0.0-rc2](https://github.com/brendanhay/amazonka/compare/2.0.0-rc2...2.0.0)

Expand Down

0 comments on commit 7353924

Please sign in to comment.