D2903: utils: add isauthorwellformed function

sheehan (Connor Sheehan) phabricator at mercurial-scm.org
Tue Mar 20 17:56:21 UTC 2018


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

REVISION SUMMARY
  Adds a function to determine if an author field is formatted
  correctly (ie "Contributor Name <something at something.com>")

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2615,6 +2615,12 @@
         r = None
     return author[author.find('<') + 1:r]
 
+_correctauthorformat = re.compile('^[^<]+\s\<[^<>]+@[^<>]+\>$')
+def isauthorwellformed(author):
+    '''Return True if the author field is well formed
+    (ie "Contributor Name <contrib at email.dom>")'''
+    return bool(_correctauthorformat.match(author))
+
 def ellipsis(text, maxlength=400):
     """Trim string to at most maxlength (default: 400) columns in display."""
     return encoding.trim(text, maxlength, ellipsis='...')



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


More information about the Mercurial-devel mailing list