Skip to content

Commit 29d50ba

Browse files
yasoobhyasoobzDean Karn
authored
add validation for base64 url without = padding (#1024)
Co-authored-by: Yasoob Haider <[email protected]> Co-authored-by: Dean Karn <[email protected]>
1 parent 1c1f70d commit 29d50ba

File tree

8 files changed

+229
-164
lines changed

8 files changed

+229
-164
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Baked-in Validations
150150
| - | - |
151151
| base64 | Base64 String |
152152
| base64url | Base64URL String |
153+
| base64rawurl | Base64RawURL String |
153154
| bic | Business Identifier Code (ISO 9362) |
154155
| bcp47_language_tag | Language tag (BCP 47) |
155156
| btc_addr | Bitcoin Address |

baked_in.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var (
129129
"file": isFile,
130130
"base64": isBase64,
131131
"base64url": isBase64URL,
132+
"base64rawurl": isBase64RawURL,
132133
"contains": contains,
133134
"containsany": containsAny,
134135
"containsrune": containsRune,
@@ -1364,6 +1365,11 @@ func isBase64URL(fl FieldLevel) bool {
13641365
return base64URLRegex.MatchString(fl.Field().String())
13651366
}
13661367

1368+
// isBase64RawURL is the validation function for validating if the current field's value is a valid base64 URL safe string without '=' padding.
1369+
func isBase64RawURL(fl FieldLevel) bool {
1370+
return base64RawURLRegex.MatchString(fl.Field().String())
1371+
}
1372+
13671373
// isURI is the validation function for validating if the current field's value is a valid URI.
13681374
func isURI(fl FieldLevel) bool {
13691375
field := fl.Field()

cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr
120120
var fld reflect.StructField
121121
var tag string
122122
var customName string
123-
123+
124124
for i := 0; i < numFields; i++ {
125125

126126
fld = typ.Field(i)

0 commit comments

Comments
 (0)