Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 567b380

Browse files
committed
common: When base64 decoding fails, try base64url decoding it
1 parent 3d3b03e commit 567b380

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

common/userinput.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ func CheckUnicode(rawInput string) (str string, err error) {
2828
var decoded []byte
2929
decoded, err = base64.StdEncoding.DecodeString(rawInput)
3030
if err != nil {
31-
return
31+
// When base64 decoding fails, automatically try again with base64url format instead
32+
var err2 error
33+
decoded, err2 = base64.URLEncoding.DecodeString(rawInput)
34+
if err2 != nil {
35+
// We use err2, so the original error message is returned if the 2nd attempt fails
36+
return
37+
}
3238
}
3339

3440
// Ensure the decoded string is valid UTF-8

0 commit comments

Comments
 (0)