mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-19 16:17:56 +00:00
Merge pull request #5031 from keaipiao/fix/easypay-error-utf8
fix(payment): preserve UTF-8 in EasyPay errors
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/payment"
|
||||
)
|
||||
@@ -477,7 +478,11 @@ func summarizeEasyPayResponse(body []byte) string {
|
||||
return "<empty>"
|
||||
}
|
||||
if len(summary) > maxEasypayErrorSummary {
|
||||
return summary[:maxEasypayErrorSummary] + "..."
|
||||
truncated := summary[:maxEasypayErrorSummary]
|
||||
for len(truncated) > 0 && !utf8.ValidString(truncated) {
|
||||
truncated = truncated[:len(truncated)-1]
|
||||
}
|
||||
return truncated + "..."
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/payment"
|
||||
)
|
||||
@@ -179,6 +180,18 @@ func TestEasyPayRefundResponseErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummarizeEasyPayResponsePreservesUTF8(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
summary := summarizeEasyPayResponse([]byte(strings.Repeat("错", 171)))
|
||||
if !utf8.ValidString(summary) {
|
||||
t.Fatalf("summarizeEasyPayResponse returned invalid UTF-8: %q", summary)
|
||||
}
|
||||
if !strings.HasSuffix(summary, "...") {
|
||||
t.Fatalf("summarizeEasyPayResponse() = %q, want truncated suffix", summary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEasyPayCustomMethodsUseConfiguredUpstreamType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user