go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.06k stars 1.29k forks source link

Failing validation using the base64url tag #1271

Open RaffaRus opened 1 month ago

RaffaRus commented 1 month ago

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)
}