Skip to content

Commit

Permalink
add validation for base64 url without = padding (#1024)
Browse files Browse the repository at this point in the history
Co-authored-by: Yasoob Haider <yasoob.haider@zomato.com>
Co-authored-by: Dean Karn <Dean.Karn@gmail.com>
  • Loading branch information
3 people committed Mar 19, 2023
1 parent 1c1f70d commit 29d50ba
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 164 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -150,6 +150,7 @@ Baked-in Validations
| - | - |
| base64 | Base64 String |
| base64url | Base64URL String |
| base64rawurl | Base64RawURL String |
| bic | Business Identifier Code (ISO 9362) |
| bcp47_language_tag | Language tag (BCP 47) |
| btc_addr | Bitcoin Address |
Expand Down
6 changes: 6 additions & 0 deletions baked_in.go
Expand Up @@ -129,6 +129,7 @@ var (
"file": isFile,
"base64": isBase64,
"base64url": isBase64URL,
"base64rawurl": isBase64RawURL,
"contains": contains,
"containsany": containsAny,
"containsrune": containsRune,
Expand Down Expand Up @@ -1364,6 +1365,11 @@ func isBase64URL(fl FieldLevel) bool {
return base64URLRegex.MatchString(fl.Field().String())
}

// isBase64RawURL is the validation function for validating if the current field's value is a valid base64 URL safe string without '=' padding.
func isBase64RawURL(fl FieldLevel) bool {
return base64RawURLRegex.MatchString(fl.Field().String())
}

// isURI is the validation function for validating if the current field's value is a valid URI.
func isURI(fl FieldLevel) bool {
field := fl.Field()
Expand Down
2 changes: 1 addition & 1 deletion cache.go
Expand Up @@ -120,7 +120,7 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr
var fld reflect.StructField
var tag string
var customName string

for i := 0; i < numFields; i++ {

fld = typ.Field(i)
Expand Down

0 comments on commit 29d50ba

Please sign in to comment.