# HG changeset patch # User Yuya Nishihara # Date 1524224309 -32400 # Node ID 5cab6f5016fa5e2c50f89bbfc2f92369efd41522 # Parent 6cf5f5b4eb57e72faeca2f4eda250b08c3b9d2b6 version: make parser more robust for rc variants and ill-formed strings diff -r 6cf5f5b4eb57 -r 5cab6f5016fa mercurial/util.py --- a/mercurial/util.py Wed Apr 18 19:02:44 2018 -0600 +++ b/mercurial/util.py Fri Apr 20 20:38:29 2018 +0900 @@ -1037,14 +1037,27 @@ (3, 9, None) >>> versiontuple(v, 4) (3, 9, None, 'rc+2-02a8fea4289b') + + >>> versiontuple(b'4.6rc0') + (4, 6, None, 'rc0') + >>> versiontuple(b'4.6rc0+12-425d55e54f98') + (4, 6, None, 'rc0+12-425d55e54f98') + >>> versiontuple(b'.1.2.3') + (None, None, None, '.1.2.3') + >>> versiontuple(b'12.34..5') + (12, 34, None, '..5') + >>> versiontuple(b'1.2.3.4.5.6') + (1, 2, 3, '.4.5.6') """ if not v: v = version() - parts = remod.split('[\+-]', v, 1) - if len(parts) == 1: - vparts, extra = parts[0], None + m = remod.match(br'(\d+(?:\.\d+){,2})[\+-]?(.*)', v) + if not m: + vparts, extra = '', v + elif m.group(2): + vparts, extra = m.groups() else: - vparts, extra = parts + vparts, extra = m.group(1), None vints = [] for i in vparts.split('.'):