fix: use the same schema encoder everywhere (#299)

properly register SpaceDelimitedArray for all instances
of schema.Encoder inside the oidc framework.

Closes #295
This commit is contained in:
Tim Möhlmann 2023-03-02 15:24:44 +02:00 committed by GitHub
parent fc1a80d274
commit 4dca29f1f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 13 deletions

View file

@ -4,9 +4,11 @@ import (
"database/sql/driver"
"encoding/json"
"fmt"
"reflect"
"strings"
"time"
"github.com/gorilla/schema"
"golang.org/x/text/language"
"gopkg.in/square/go-jose.v2"
)
@ -125,6 +127,16 @@ func (s SpaceDelimitedArray) Value() (driver.Value, error) {
return strings.Join(s, " "), nil
}
// NewEncoder returns a schema Encoder with
// a registered encoder for SpaceDelimitedArray.
func NewEncoder() *schema.Encoder {
e := schema.NewEncoder()
e.RegisterEncoder(SpaceDelimitedArray{}, func(value reflect.Value) string {
return value.Interface().(SpaceDelimitedArray).Encode()
})
return e
}
type Time time.Time
func (t *Time) UnmarshalJSON(data []byte) error {