D2959: stringutil: add isauthorwellformed function
sheehan (Connor Sheehan)
phabricator at mercurial-scm.org
Thu Mar 29 14:10:36 UTC 2018
sheehan updated this revision to Diff 7359.
sheehan marked 3 inline comments as done.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D2959?vs=7343&id=7359
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(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
To: sheehan, #hg-reviewers, yuja
Cc: yuja, av6, mercurial-devel
More information about the Mercurial-devel
mailing list