Mercurial > hg-stable
changeset 2523:4ab59a3acd16
validate the resulting date in parsedate
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Fri, 30 Jun 2006 18:48:06 +0200 |
parents | 85f796baab10 |
children | c1974f65d781 |
files | mercurial/changelog.py mercurial/util.py |
diffstat | 2 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changelog.py Fri Jun 30 18:47:35 2006 +0200 +++ b/mercurial/changelog.py Fri Jun 30 18:48:06 2006 +0200 @@ -39,16 +39,7 @@ def add(self, manifest, list, desc, transaction, p1=None, p2=None, user=None, date=None): if date: - # validate explicit (probably user-specified) date and - # time zone offset. values must fit in signed 32 bits for - # current 32-bit linux runtimes. timezones go from UTC-12 - # to UTC+14 - when, offset = util.parsedate(date) - if abs(when) > 0x7fffffff: - raise ValueError(_('date exceeds 32 bits: %d') % when) - if offset < -50400 or offset > 43200: - raise ValueError(_('impossible time zone offset: %d') % offset) - parseddate = "%d %d" % (when, offset) + parseddate = "%d %d" % util.parsedate(date) else: parseddate = "%d %d" % util.makedate() list.sort()
--- a/mercurial/util.py Fri Jun 30 18:47:35 2006 +0200 +++ b/mercurial/util.py Fri Jun 30 18:48:06 2006 +0200 @@ -882,13 +882,25 @@ formats.""" try: when, offset = map(int, string.split(' ')) - return when, offset - except ValueError: pass - for format in formats: - try: - return strdate(string, format) - except ValueError: pass - raise ValueError(_('invalid date: %r') % string) + except ValueError: + for format in formats: + try: + when, offset = strdate(string, format) + except ValueError: + pass + else: + break + else: + raise ValueError(_('invalid date: %r') % string) + # validate explicit (probably user-specified) date and + # time zone offset. values must fit in signed 32 bits for + # current 32-bit linux runtimes. timezones go from UTC-12 + # to UTC+14 + if abs(when) > 0x7fffffff: + raise ValueError(_('date exceeds 32 bits: %d') % when) + if offset < -50400 or offset > 43200: + raise ValueError(_('impossible time zone offset: %d') % offset) + return when, offset def shortuser(user): """Return a short representation of a user name or email address."""