mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 11:21:16 +00:00
Encode content for {create,update}_file (#1267)
If a byte object (for Python 3) was passed into either create_file or update_file, it was attempted to be co-erced into a bytearray, which failed. Check for encoded content before we encode it into bytes and then base64 encode it. Fixes #1266
This commit is contained in:
@@ -1645,9 +1645,9 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
or isinstance(committer, github.InputGitAuthor), \
|
||||
'committer must be a github.InputGitAuthor object'
|
||||
|
||||
content = b64encode(bytearray(content, 'utf-8'))
|
||||
if isinstance(content, bytes):
|
||||
content = content.decode('utf-8')
|
||||
if not isinstance(content, bytes):
|
||||
content = content.encode('utf-8')
|
||||
content = b64encode(content).decode('utf-8')
|
||||
put_parameters = {'message': message, 'content': content}
|
||||
|
||||
if branch is not github.GithubObject.NotSet:
|
||||
@@ -1702,9 +1702,9 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
or isinstance(committer, github.InputGitAuthor), \
|
||||
'committer must be a github.InputGitAuthor object'
|
||||
|
||||
content = b64encode(bytearray(content, 'utf-8'))
|
||||
if isinstance(content, bytes):
|
||||
content = content.decode('utf-8')
|
||||
if not isinstance(content, bytes):
|
||||
content = content.encode('utf-8')
|
||||
content = b64encode(content).decode('utf-8')
|
||||
|
||||
put_parameters = {'message': message, 'content': content,
|
||||
'sha': sha}
|
||||
|
||||
Reference in New Issue
Block a user