From 2c51c555a6a2a53d6d05a7b0a9e4208984972212 Mon Sep 17 00:00:00 2001 From: Mitar Date: Wed, 5 Aug 2020 12:34:10 -0700 Subject: [PATCH] refactor: Copy all values when sanitizing --- request.go | 4 ++-- request_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/request.go b/request.go index 276411218..2a51b48f6 100644 --- a/request.go +++ b/request.go @@ -186,8 +186,8 @@ func (a *Request) Sanitize(allowedParameters []string) Requester { b.ID = a.GetID() b.Form = url.Values{} for k := range a.Form { - if _, ok := allowed[k]; ok { - b.Form.Add(k, a.Form.Get(k)) + if allowed[k] { + b.Form[k] = a.Form[k] } } diff --git a/request_test.go b/request_test.go index b1b674e5d..21be33258 100644 --- a/request_test.go +++ b/request_test.go @@ -92,7 +92,7 @@ func TestSanitizeRequest(t *testing.T) { GrantedScope: []string{"asdf"}, Form: url.Values{ "foo": []string{"fasdf"}, - "bar": []string{"fasdf", "fasdf"}, + "bar": []string{"fasdf", "faaaa"}, "baz": []string{"fasdf"}, }, Session: new(DefaultSession), @@ -100,13 +100,16 @@ func TestSanitizeRequest(t *testing.T) { b := a.Sanitize([]string{"bar", "baz"}) assert.NotEqual(t, a.Form.Encode(), b.GetRequestForm().Encode()) + assert.Empty(t, b.GetRequestForm().Get("foo")) assert.Equal(t, "fasdf", b.GetRequestForm().Get("bar")) + assert.Equal(t, []string{"fasdf", "faaaa"}, b.GetRequestForm()["bar"]) assert.Equal(t, "fasdf", b.GetRequestForm().Get("baz")) + assert.Equal(t, "fasdf", a.GetRequestForm().Get("foo")) assert.Equal(t, "fasdf", a.GetRequestForm().Get("bar")) + assert.Equal(t, []string{"fasdf", "faaaa"}, a.GetRequestForm()["bar"]) assert.Equal(t, "fasdf", a.GetRequestForm().Get("baz")) - assert.Equal(t, "fasdf", a.GetRequestForm().Get("foo")) } func TestIdentifyRequest(t *testing.T) {