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

base64url should not require padding #1002

Closed
2 tasks done
maticmeznar opened this issue Sep 25, 2022 · 4 comments · Fixed by #1024
Closed
2 tasks done

base64url should not require padding #1002

maticmeznar opened this issue Sep 25, 2022 · 4 comments · Fixed by #1024

Comments

@maticmeznar
Copy link

maticmeznar commented Sep 25, 2022

  • I have looked at the documentation here first?
  • 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"))
}
@zemzale
Copy link
Member

zemzale commented Oct 5, 2022

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

@maticmeznar
Copy link
Author

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

@zemzale
Copy link
Member

zemzale commented Oct 5, 2022

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

@yasoobh
Copy link
Contributor

yasoobh commented Nov 8, 2022

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

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

Successfully merging a pull request may close this issue.

3 participants