fix: AWS Lambda: Avoid text-encoding binary data (#1235)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
So far, the AWS Lambda adapter has used `atob` to convert a Base64-encoded request body to a binary. However, `atob` returns a string, and passing that to the `Request` constructor (at least on Node.js, which Lambda runs on) results in the binary string being encoded as UTF-8. This means that if the request body contains bytes which are not in the ASCII range, they are replaced with UTF-8 multi-byte encodings, which leads to `c.req.blob()`, `c.req.formData()`, etc. returning the wrong binary data! This commit fixes the issue by replacing `atob(body)` with `Buffer.from(body, 'base64')`, which does not have that problem. The `Buffer` can be directly passed as body for `new Request()` because it implements the `Uint8Array` interface. While this makes the AWS Lambda adapter depend directly on the "node:buffer" module, this should be fine because AWS Lambda functions always run on Node.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+28 added−1 removed
- tests:+26 added−0 removed
- other:+2 added−1 removed