From 9694fdc3f1bb0a35b0691a1961b3561e5411819b Mon Sep 17 00:00:00 2001 From: James Elliott Date: Tue, 24 Jan 2023 21:47:54 +1100 Subject: [PATCH] feat(protocol): ignore padding for base64 url encoding This adds support to ignore the trailing padding of base64 URL encoded bytes. --- protocol/base64.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/protocol/base64.go b/protocol/base64.go index 99362b2..37a151b 100644 --- a/protocol/base64.go +++ b/protocol/base64.go @@ -22,8 +22,13 @@ func (e *URLEncodedBase64) UnmarshalJSON(data []byte) error { return nil } + // TODO: Investigate this line. It is commented as trimming the leading spaces but appears to trim the leading and trailing double quotes instead. // Trim the leading spaces data = bytes.Trim(data, "\"") + + // Trim the trailing equal characters. + data = bytes.TrimRight(data, "=") + out := make([]byte, base64.RawURLEncoding.DecodedLen(len(data))) n, err := base64.RawURLEncoding.Decode(out, data) if err != nil {