Repository: honojs/hono (TypeScript)

Issue:
SVG Content Type incorrectly encoded as base64
### What version of Hono are you using?

3.11.1

### What runtime/platform is your app running on?

AWS Lambda

### What steps can reproduce the bug?

Return an SVG in a route with

```
c.header('Content-Type', 'image/svg+xml;charset=utf-8');
return c.body(svgString)
```

results in it being base64 encoded.

### What is the expected behavior?

SVG is just text, so it shouldn't need to be encoded before being returned to API Gateway.

PR to fix the regexp in #1788 

### What do you see instead?

It gets encoded, so you cannot render the SVG in a browser.

### Additional information

The relevant code is here: https://github.com/honojs/hono/blame/main/src/adapter/aws-lambda/handler.ts#L264 that was added as part of https://github.com/honojs/hono/pull/1091


Discussion:

Patch:
diff --git a/src/adapter/aws-lambda/handler.ts b/src/adapter/aws-lambda/handler.ts
index 30d40c33c..58557a67a 100644
--- a/src/adapter/aws-lambda/handler.ts
+++ b/src/adapter/aws-lambda/handler.ts
@@ -261,7 +261,7 @@ const isProxyEventV2 = (event: LambdaEvent): event is APIGatewayProxyEventV2 =>
 }
 
 export const isContentTypeBinary = (contentType: string) => {
-  return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml)$/.test(
+  return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(
     contentType
   )
 }
diff --git a/src/adapter/lambda-edge/handler.ts b/src/adapter/lambda-edge/handler.ts
index 45d390665..5316eaf8c 100644
--- a/src/adapter/lambda-edge/handler.ts
+++ b/src/adapter/lambda-edge/handler.ts
@@ -158,7 +158,7 @@ const createRequest = (event: CloudFrontEdgeEvent) => {
 }
 
 export const isContentTypeBinary = (contentType: string) => {
-  return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml)$/.test(
+  return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(
     contentType
   )
 }


Test patch:
diff --git a/src/adapter/aws-lambda/handler.test.ts b/src/adapter/aws-lambda/handler.test.ts
index 554458fd5..f35dcafe9 100644
--- a/src/adapter/aws-lambda/handler.test.ts
+++ b/src/adapter/aws-lambda/handler.test.ts
@@ -4,6 +4,8 @@ describe('isContentTypeBinary', () => {
   it('Should determine whether it is binary', () => {
     expect(isContentTypeBinary('image/png')).toBe(true)
     expect(isContentTypeBinary('font/woff2')).toBe(true)
+    expect(isContentTypeBinary('image/svg+xml')).toBe(false)
+    expect(isContentTypeBinary('image/svg+xml; charset=UTF-8')).toBe(false)
     expect(isContentTypeBinary('text/plain')).toBe(false)
     expect(isContentTypeBinary('text/plain; charset=UTF-8')).toBe(false)
     expect(isContentTypeBinary('text/css')).toBe(false)
diff --git a/src/adapter/lambda-edge/handler.test.ts b/src/adapter/lambda-edge/handler.test.ts
index 4ba5744a3..bfcded0da 100644
--- a/src/adapter/lambda-edge/handler.test.ts
+++ b/src/adapter/lambda-edge/handler.test.ts
@@ -4,6 +4,8 @@ describe('isContentTypeBinary', () => {
   it('Should determine whether it is binary', () => {
     expect(isContentTypeBinary('image/png')).toBe(true)
     expect(isContentTypeBinary('font/woff2')).toBe(true)
+    expect(isContentTypeBinary('image/svg+xml')).toBe(false)
+    expect(isContentTypeBinary('image/svg+xml; charset=UTF-8')).toBe(false)
     expect(isContentTypeBinary('text/plain')).toBe(false)
     expect(isContentTypeBinary('text/plain; charset=UTF-8')).toBe(false)
     expect(isContentTypeBinary('text/css')).toBe(false)