mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
fix: validate UTF-8 before storing request_body as JSONB
PostgreSQL JSONB columns require valid UTF-8 encoding. Skip storing request_body if it contains invalid UTF-8 byte sequences (e.g. from non-UTF-8 terminal encodings). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||
)
|
||||
@@ -23,7 +24,7 @@ func (r *SoraTaskRepository) Create(ctx context.Context, task *service.SoraTask)
|
||||
s := string(b)
|
||||
charStr = &s
|
||||
}
|
||||
if len(task.RequestBody) > 0 {
|
||||
if len(task.RequestBody) > 0 && utf8.Valid(task.RequestBody) {
|
||||
s := string(task.RequestBody)
|
||||
reqStr = &s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user