D2959: stringutil: add isauthorwellformed function

sheehan (Connor Sheehan) phabricator at mercurial-scm.org
Fri Mar 30 08:56:14 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf8e1f48de118: stringutil: add isauthorwellformed function (authored by sheehan, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D2959?vs=7359&id=7379#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2959?vs=7359&id=7379

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
@@ -131,6 +131,29 @@
         r = None
     return author[author.find('<') + 1:r]
 
+_correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
+
+def isauthorwellformed(author):
+    '''Return True if the author field is well formed
+    (ie "Contributor Name <contrib at email.dom>")
+
+    >>> isauthorwellformed(b'Good Author <good at author.com>')
+    True
+    >>> isauthorwellformed(b'Author <good at author.com>')
+    True
+    >>> isauthorwellformed(b'Bad Author')
+    False
+    >>> isauthorwellformed(b'Bad Author <author at author.com')
+    False
+    >>> isauthorwellformed(b'Bad Author author at author.com')
+    False
+    >>> isauthorwellformed(b'<author at author.com>')
+    False
+    >>> isauthorwellformed(b'Bad Author <author>')
+    False
+    '''
+    return _correctauthorformat.match(author) is not None
+
 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, yuja
Cc: yuja, av6, mercurial-devel


More information about the Mercurial-devel mailing list