Skip to content

Commit 8fb47ee

Browse files
authored
Accept empty base64 inputs (#1013)
1 parent e2db596 commit 8fb47ee

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var rxHostname = regexp.MustCompile(`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61
4747
var rxURITemplate = regexp.MustCompile("^([^{]*({[^}]*})?)*$")
4848
var rxJSONPointer = regexp.MustCompile("^(?:/(?:[^~/]|~0|~1)*)*$")
4949
var rxRelJSONPointer = regexp.MustCompile("^(?:0|[1-9][0-9]*)(?:#|(?:/(?:[^~/]|~0|~1)*)*)$")
50-
var rxBase64 = regexp.MustCompile(`^[a-zA-Z0-9+/_-]+=*$`)
50+
var rxBase64 = regexp.MustCompile(`^[a-zA-Z0-9+/_-]*=*$`)
5151

5252
func mapTo[A, B any](s []A, f func(A) B) []B {
5353
r := make([]B, len(s))

validate_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,27 @@ var validateTests = []struct {
621621
}](),
622622
input: map[string]any{"value": []byte("ABCD")},
623623
},
624+
{
625+
name: "base64 empty byte success",
626+
typ: reflect.TypeFor[struct {
627+
Value []byte "json:\"value\""
628+
}](),
629+
input: map[string]any{"value": []byte("")},
630+
},
624631
{
625632
name: "base64 string success",
626633
typ: reflect.TypeFor[struct {
627634
Value string "json:\"value\" encoding:\"base64\""
628635
}](),
629636
input: map[string]any{"value": "ABCD"},
630637
},
638+
{
639+
name: "base64 empty string success",
640+
typ: reflect.TypeFor[struct {
641+
Value string "json:\"value\" encoding:\"base64\""
642+
}](),
643+
input: map[string]any{"value": ""},
644+
},
631645
{
632646
name: "base64 fail",
633647
typ: reflect.TypeFor[struct {

0 commit comments

Comments
 (0)