diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py --- a/mercurial/utils/stringutil.py +++ b/mercurial/utils/stringutil.py @@ -286,3 +286,25 @@ If s is not a valid boolean, returns None. """ return _booleans.get(s.lower(), None) + +_correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$') +def isauthorwellformed(author): + '''Return True if the author field is well formed + (ie "Contributor Name ") + + >>> isauthorwellformed(b'Good Author ') + True + >>> isauthorwellformed(b'Author ') + True + >>> isauthorwellformed(b'Bad Author') + False + >>> isauthorwellformed(b'Bad Author >> isauthorwellformed(b'Bad Author author@author.com') + False + >>> isauthorwellformed(b'') + False + >>> isauthorwellformed(b'Bad Author ') + False + ''' + return _correctauthorformat.match(author) is not None