oauth icon indicating copy to clipboard operation
oauth copied to clipboard

Space not properly escaped

Open pchristopher1275 opened this issue 10 years ago • 1 comments

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)
 }

pchristopher1275 avatar Oct 14 '15 18:10 pchristopher1275

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.

jiridanek avatar Jan 16 '16 14:01 jiridanek