Skip to content

Commit 90d6600

Browse files
committed
Found a very critical bug in github3/models.
In _put() I had not taken into account that there are instances where put is used with data. The instances where it is not it is *required* to send '0' as the Content-Length header. Other than that, requests should handle the content length. It was a simple fix.
1 parent cfe8d85 commit 90d6600

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

github3/issues.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ def remove_label(self, name):
320320
"""Removes label ``name`` from this issue.
321321
322322
:param str name: (required), name of the label to remove
323-
:returns: bool
323+
:returns: list of labels remaining
324324
"""
325325
url = self._build_url('labels', name, base_url=self._api)
326-
return self._boolean(self._delete(url), 200, 404)
326+
return self._json(self._delete(url), 200)
327327

328328
@requires_auth
329329
def remove_all_labels(self):
@@ -343,7 +343,7 @@ def replace_labels(self, labels):
343343
:returns: bool
344344
"""
345345
url = self._build_url('labels', base_url=self._api)
346-
return self._boolean(self._put(url, dumps(labels)), 200, 404)
346+
return self._boolean(self._put(url, data=dumps(labels)), 200, 404)
347347

348348
@requires_auth
349349
def reopen(self):

github3/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def _post(self, url, data=None, **kwargs):
120120
def _put(self, url, **kwargs):
121121
req = False
122122
if self._remaining > 0:
123-
kwargs.update(headers={'Content-Length': '0'})
123+
if 'data' not in kwargs:
124+
kwargs.update(headers={'Content-Length': '0'})
124125
req = self._session.put(url, **kwargs)
125126
return req
126127

tests/test_issues.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ def test_with_auth(self):
113113
issue.edit(old_title, old_body)
114114
expect(issue.edit(None)).is_False()
115115
issue.add_labels('wontfix', 'Enhancement')
116-
expect(issue.remove_label('wontfix')).is_True()
117-
expect(issue.remove_label('wontfix')).is_False()
118-
expect(issue.replace_labels('invalid', 'duplicate')).is_True()
116+
expect(issue.remove_label('wontfix')).isinstance(list)
117+
expect(issue.remove_label('wontfix')).isinstance(list)
118+
expect(issue.replace_labels(['invalid', 'duplicate'])).is_True()
119119
expect(issue.remove_all_labels()).is_True()
120120

121121

0 commit comments

Comments
 (0)