Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Properly handle non-ascii characters in passwords

Explicitly encode the username:password auth string as UTF-8 before
base64'ing it. Should fix #22.
  • Loading branch information...
commit e15e445b2e6f5851568d976d6d8aefb5da2b3fad 1 parent 1bb9334
@technocoreai technocoreai authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 gist.py
View
10 gist.py
@@ -36,6 +36,10 @@ def get_credentials():
raise MissingCredentialsException()
return (username, password)
+def basic_auth_string():
+ auth_string = u'%s:%s' % get_credentials()
+ return auth_string.encode('utf-8')
+
if sublime.platform() == 'osx':
# Keychain support
# Instead of Gist.sublime-settings, fetch username and password from the user's github.com keychain entry
@@ -209,7 +213,7 @@ def api_request_native(url, data=None, method=None):
request = urllib2.Request(url)
if method:
request.get_method = lambda: method
- request.add_header('Authorization', 'Basic ' + base64.urlsafe_b64encode("%s:%s" % get_credentials()))
+ request.add_header('Authorization', 'Basic ' + base64.urlsafe_b64encode(basic_auth_string()))
request.add_header('Accept', 'application/json')
request.add_header('Content-Type', 'application/json')
@@ -244,9 +248,7 @@ def named_tempfile():
def api_request_curl(url, data=None, method=None):
command = ["curl", '-K', '-', url]
- authorization_string = '-u "%s:%s"' % get_credentials()
-
- config = [authorization_string,
+ config = ['-u ' + basic_auth_string(),
'--header "Accept: application/json"',
'--header "Content-Type: application/json"',
"--silent"]
Please sign in to comment.
Something went wrong with that request. Please try again.