Skip to content

Commit cc5de5e

Browse files
committed
use decodeUtf8Lenient instead of decodeUtf8
1 parent 0f7ea76 commit cc5de5e

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Revision history for wai-handler-hal
22

3+
## 0.5.0.0 -- 2025-12-14
4+
5+
- Breaking change: Replace unsafe `decodeUtf8` with `decodeUtf8Lenient`
6+
for header and body decoding. Invalid UTF-8 sequences are now replaced
7+
with Unicode replacement characters (U+FFFD) instead of throwing exceptions.
8+
39
## 0.4.0.2 -- 2025-08-14
410

511
- Union single and multi-value query parameters and headers when

src/Network/Wai/Handler/Hal.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ constructQuery = foldMap expandParamList . HashMap.toList
329329
getHeader :: HeaderName -> HalRequest.ProxyRequest a -> Maybe ByteString
330330
getHeader h =
331331
fmap Text.encodeUtf8
332-
. HashMap.lookup (CI.map Text.decodeUtf8 h)
332+
. HashMap.lookup (CI.map Text.decodeUtf8Lenient h)
333333
. HalRequest.headers
334334

335335
-- | Convert a WAI 'Wai.Response' into a hal
@@ -369,11 +369,11 @@ readFilePart path mPart = withFile path ReadMode $ \h -> do
369369
createProxyBody :: Options -> MediaType -> ByteString -> HalResponse.ProxyBody
370370
createProxyBody opts contentType body =
371371
HalResponse.ProxyBody
372-
{ HalResponse.contentType = Text.decodeUtf8 $ renderHeader contentType,
372+
{ HalResponse.contentType = Text.decodeUtf8Lenient $ renderHeader contentType,
373373
HalResponse.serialized =
374374
if isBase64Encoded
375-
then Text.decodeUtf8 $ Base64.encode body
376-
else Text.decodeUtf8 body,
375+
then Text.decodeUtf8Lenient $ Base64.encode body
376+
else Text.decodeUtf8Lenient body,
377377
HalResponse.isBase64Encoded
378378
}
379379
where
@@ -385,8 +385,8 @@ addHeaders headers response = foldl' addHeader response headers
385385
where
386386
addHeader r (hName, hValue) =
387387
HalResponse.addHeader
388-
(Text.decodeUtf8 $ CI.original hName)
389-
(Text.decodeUtf8 hValue)
388+
(Text.decodeUtf8Lenient $ CI.original hName)
389+
(Text.decodeUtf8Lenient hValue)
390390
r
391391

392392
-- | Try to find the content-type of a response, given the response

wai-handler-hal.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: wai-handler-hal
3-
version: 0.4.0.2
3+
version: 0.5.0.0
44
synopsis: Wrap WAI applications to run on AWS Lambda
55
description:
66
This library provides a function 'Network.Wai.Handler.Hal.run' to

0 commit comments

Comments
 (0)