Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/utils/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ func Base64DecodeConverter(value interface{}) interface{} {
}
decoded, err := base64.StdEncoding.DecodeString(str)
if err != nil || !utf8.Valid(decoded) {
// Fall back to raw URL-safe Base64 (no padding); some backends use
// URL-safe encoding without padding.
decoded, err = base64.RawURLEncoding.DecodeString(str)
// Fall back to URL-safe Base64. Some backends keep padding while others
// omit it, so support both variants before giving up.
decoded, err = base64.URLEncoding.DecodeString(str)
if err != nil || !utf8.Valid(decoded) {
decoded, err = base64.RawURLEncoding.DecodeString(str)
}
if err != nil || !utf8.Valid(decoded) {
return value
}
Expand Down
5 changes: 5 additions & 0 deletions internal/utils/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ func TestBase64DecodeConverter(t *testing.T) {
input: "aGVsbG8-d29ybGQ=", // URL-safe 编码
want: "hello>world",
},
{
name: "URL-safe Base64 无填充解码",
input: "aGVsbG8_d29ybGQ", // URL-safe 编码 (no padding)
want: "hello?world",
},
{
name: "非 Base64 字符串原样返回",
input: "not-base64-!!!",
Expand Down