validator icon indicating copy to clipboard operation
validator copied to clipboard

base64url should not require padding

Open maticmeznar opened this issue 2 years ago • 4 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:

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 avatar Sep 25 '22 09:09 maticmeznar

@maticmeznar Could you provide a simple example of the faulty validation?

zemzale avatar Oct 05 '22 06:10 zemzale

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

maticmeznar avatar Oct 05 '22 07:10 maticmeznar

Will see what can be done about this, or feel free to open a PR yourself, since this indeed is a bug.

zemzale avatar Oct 05 '22 08:10 zemzale

@zemzale - i have opened a pull request for this. Can you please check?

yasoobh avatar Nov 08 '22 08:11 yasoobh