Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space not properly escaped #40

Open
pchristopher1275 opened this issue Oct 14, 2015 · 1 comment
Open

Space not properly escaped #40

pchristopher1275 opened this issue Oct 14, 2015 · 1 comment

Comments

@pchristopher1275
Copy link

I was getting signature failures when a query parameter had a properly escaped space. I replaced the existing escape method with url.QueryEscape and fixed. Patch below.

diff --git a/oauth.go b/oauth.go
index d8e0ea2..07cccac 100644
--- a/oauth.go
+++ b/oauth.go
@@ -957,23 +957,7 @@ func (s *RSASigner) SignatureMethod() string {
 }

 func escape(s string) string {
-       t := make([]byte, 0, 3*len(s))
-       for i := 0; i < len(s); i++ {
-               c := s[i]
-               if isEscapable(c) {
-                       t = append(t, '%')
-                       t = append(t, "0123456789ABCDEF"[c>>4])
-                       t = append(t, "0123456789ABCDEF"[c&15])
-               } else {
-                       t = append(t, s[i])
-               }
-       }
-       return string(t)
-}
-
-func isEscapable(b byte) bool {
-       return !('A' <= b && b <= 'Z' || 'a' <= b && b <= 'z' || '0' <= b && b <= '9' || b == '-' || b == '.' || b == '_' || b == '~')
-
+       return url.QueryEscape(s)
 }
@jiridanek
Copy link

According to this https://dev.twitter.com/oauth/overview/creating-signatures, space should be encoded into %20, not + character. So the oauth package does this correctly. Who is telling you your signatures are wrong? Maybe they implemented this incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants