Skip to content

Commit ef86807

Browse files
pscohndghubble
authored andcommitted
Fix oauth_callback_confirmed comparison when server returns extra whitespace
1 parent bb56188 commit ef86807

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"net/http"
99
"net/url"
10+
"strings"
1011
)
1112

1213
const (
@@ -89,7 +90,7 @@ func (c *Config) RequestToken() (requestToken, requestSecret string, err error)
8990
}
9091

9192
// ParseQuery to decode URL-encoded application/x-www-form-urlencoded body
92-
values, err := url.ParseQuery(string(body))
93+
values, err := url.ParseQuery(strings.TrimSpace(string(body)))
9394
if err != nil {
9495
return "", "", err
9596
}

config_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func newRequestTokenServer(t *testing.T, data url.Values) *httptest.Server {
6363
assert.Equal(t, "POST", req.Method)
6464
assert.NotEmpty(t, req.Header.Get("Authorization"))
6565
w.Header().Set(contentType, formContentType)
66-
w.Write([]byte(data.Encode()))
66+
// Add a newline to ensure parsing works for servers that return extra whitespace
67+
w.Write([]byte(data.Encode() + "\n"))
6768
})
6869
}
6970

@@ -91,7 +92,7 @@ func newUnparseableBodyServer() *httptest.Server {
9192
}
9293

9394
func TestConfigRequestToken(t *testing.T) {
94-
expectedToken := "reqest_token"
95+
expectedToken := "request_token"
9596
expectedSecret := "request_secret"
9697
data := url.Values{}
9798
data.Add("oauth_token", expectedToken)
@@ -124,7 +125,7 @@ func TestConfigRequestToken_InvalidRequestTokenURL(t *testing.T) {
124125
}
125126

126127
func TestConfigRequestToken_CallbackNotConfirmed(t *testing.T) {
127-
const expectedToken = "reqest_token"
128+
const expectedToken = "request_token"
128129
const expectedSecret = "request_secret"
129130
data := url.Values{}
130131
data.Add("oauth_token", expectedToken)

0 commit comments

Comments
 (0)