Skip to content

Commit

Permalink
Expanded parse_timezone to accept double-negatives to be consistent w…
Browse files Browse the repository at this point in the history
…ith cgit implementation. Fixes #697828.
  • Loading branch information
jaraco committed Mar 3, 2012
1 parent b575ecd commit a6b19fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dulwich/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ def __iter__(self):
def add(self, name, mode, hexsha):
"""Add an entry to the tree.
:param mode: The mode of the entry as an integral type. Not all
:param mode: The mode of the entry as an integral type. Not all
possible modes are supported by git; see check() for details.
:param name: The name of the entry, as a string.
:param hexsha: The hex SHA of the entry as a string.
Expand Down Expand Up @@ -989,8 +989,16 @@ def parse_timezone(text):
and a boolean indicating whether this was a UTC timezone
prefixed with a negative sign (-0000).
"""
offset = int(text)
negative_utc = (offset == 0 and text[0] == '-')
# cgit parses the first character as the sign, and the rest
# as an integer (using strtol), which could also be negative.
# We do the same for compatibility. See #697828.
if not text[0] in '+-':
raise ValueError("Timezone must start with + or - (%(text)s)" % vars())
sign = text[0]
offset = int(text[1:])
if sign == '-':
offset = -offset
negative_utc = (offset == 0 and sign == '-')
signum = (offset < 0) and -1 or 1
offset = abs(offset)
hours = int(offset / 100)
Expand Down
3 changes: 3 additions & 0 deletions dulwich/tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,6 @@ def test_format_timezone_pdt_half(self):
def test_parse_timezone_pdt_half(self):
self.assertEquals((((-4 * 60) - 40) * 60, False),
parse_timezone("-0440"))

def test_parse_timezone_double_negative(self):
self.assertEquals(parse_timezone("+0700"), parse_timezone("--700"))

0 comments on commit a6b19fe

Please sign in to comment.