mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +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}
|
||||
|
||||
+1
-1
@@ -548,7 +548,7 @@ class Repository(Framework.TestCase):
|
||||
|
||||
def testCreateFile(self):
|
||||
newFile = 'doc/testCreateUpdateDeleteFile.md'
|
||||
content = 'Hello world'
|
||||
content = 'Hello world'.encode()
|
||||
self.repo.create_file(
|
||||
path=newFile, message='Create file for testCreateFile', content=content,
|
||||
branch="master", committer=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"),
|
||||
|
||||
Reference in New Issue
Block a user