Skip to content

Commit

Permalink
refactor: Copy all values when sanitizing
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Aug 5, 2020
1 parent b0d5fea commit 2c51c55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}

Expand Down
7 changes: 5 additions & 2 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,24 @@ 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),
}

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) {
Expand Down

0 comments on commit 2c51c55

Please sign in to comment.