Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty pointer string with omitempty,base64 get invalid err #1129

Open
JokerCatz opened this issue Jul 21, 2023 · 1 comment
Open

empty pointer string with omitempty,base64 get invalid err #1129

JokerCatz opened this issue Jul 21, 2023 · 1 comment

Comments

@JokerCatz
Copy link

  • [v] I have looked at the documentation here first?
  • [v] I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10: v10

Issue, Question or Enhancement:

if empty pointer string with omitempty,base64 will get base64 error , in doc say if need allow empty string , just use omitempty, original doc :

This validates that a string value contains a valid base64 value. Although an empty string is valid base64 this will report an empty string as an error, if you wish to accept an empty string as valid you can use this with the omitempty tag.

Code sample, to showcase or reproduce:

package main

import (
	"github.com/go-playground/validator/v10"
)

func main() {
	emptyString := ""
	data := struct {
		Str        string  `validate:"omitempty,base64,max=1500"`
		StrPointer *string `validate:"omitempty,base64,max=1500"`
	}{
		Str:        emptyString,
		StrPointer: &emptyString,
	}
	panic(validator.New().Struct(data))
}

// => panic: Key: 'StrPointer' Error:Field validation for 'StrPointer' failed on the 'base64' tag
@Zvirovyi
Copy link

v9 also has this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants