validator
validator copied to clipboard
base64url should not require padding
- [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:
base64url validator is faulty. It requires padding even though padding is optional in URL safe encoding.
Code sample, to showcase or reproduce:
package main
import (
"encoding/base64"
"fmt"
"github.com/go-playground/validator/v10"
)
func main() {
msg := "hello"
msgB64url := base64.RawURLEncoding.EncodeToString([]byte(msg))
val := validator.New()
fmt.Println(msgB64url) // prints "aGVsbG8"
fmt.Println(val.Var(msgB64url, "base64url"))
}
@maticmeznar Could you provide a simple example of the faulty validation?
Here is a an example code. val.Var should not return an error.
package main
import (
"encoding/base64"
"fmt"
"github.com/go-playground/validator/v10"
)
func main() {
msg := "hello"
msgB64url := base64.RawURLEncoding.EncodeToString([]byte(msg))
val := validator.New()
fmt.Println(msgB64url) // prints "aGVsbG8"
fmt.Println(val.Var(msgB64url, "base64url"))
}
Will see what can be done about this, or feel free to open a PR yourself, since this indeed is a bug.
@zemzale - i have opened a pull request for this. Can you please check?