validator icon indicating copy to clipboard operation
validator copied to clipboard

Failing validation using the base64url tag

Open RaffaRus opened this issue 1 year ago • 0 comments

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

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

Hello! First of all thanks for this super useful package!

I had trouble using the base64url tag. Below a sample code. As far as I understood, the trailing '=' are optional in the base64url standard defined here, however, the validation fails if they are missing. It seems that there could be a problem with the RegExp defined in validator/redexes.go (here)

Code sample, to showcase or reproduce:

package main

import (
	"fmt"

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

type Stuff struct {
	Field string `validate:"required,base64url"`
}

func main() {
	v := validator.New()
	err := v.Struct(Stuff{Field: "YWFzZHdkQVNEIQ=="})
	fmt.Println("errors with = :", err)
	err = v.Struct(Stuff{Field: "YWFzZHdkQVNEIQ"})
	fmt.Println("errors without = :", err)
}

RaffaRus avatar May 29 '24 13:05 RaffaRus