D2959: stringutil: add isauthorwellformed function

sheehan (Connor Sheehan) phabricator at mercurial-scm.org
Tue Mar 27 16:04:46 UTC 2018


sheehan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The regular expression for this function formerly lived at
  https://hg.mozilla.org/hgcustom/version-control-tools/file/tip/hghooks/mozhghooks/author_format.py#l13

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2959

AFFECTED FILES
  mercurial/utils/stringutil.py

CHANGE DETAILS

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('^[^<]+\s\<[^<>]+@[^<>]+\>$')
+def isauthorwellformed(author):
+    '''Return True if the author field is well formed
+    (ie "Contributor Name <contrib at email.dom>")
+
+    >>> isauthorwellformed('Good Author <good at author.com>')
+    True
+    >>> isauthorwellformed('Author <good at author.com>')
+    True
+    >>> isauthorwellformed('Bad Author')
+    False
+    >>> isauthorwellformed('Bad Author <author at author.com')
+    False
+    >>> isauthorwellformed('Bad Author author at author.com')
+    False
+    >>> isauthorwellformed('<author at author.com>')
+    False
+    >>> isauthorwellformed('Bad Author <author>')
+    False
+    '''
+    return bool(_correctauthorformat.match(author))



To: sheehan, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list