diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -290,31 +290,7 @@ @templatefilter('person') def person(author): - """Any text. Returns the name before an email address, - interpreting it as per RFC 5322. - - >>> person(b'foo@bar') - 'foo' - >>> person(b'Foo Bar ') - 'Foo Bar' - >>> person(b'"Foo Bar" ') - 'Foo Bar' - >>> person(b'"Foo \"buz\" Bar" ') - 'Foo "buz" Bar' - >>> # The following are invalid, but do exist in real-life - ... - >>> person(b'Foo "buz" Bar ') - 'Foo "buz" Bar' - >>> person(b'"Foo Bar ') - 'Foo Bar' - """ - if '@' not in author: - return author - f = author.find('<') - if f != -1: - return author[:f].strip(' "').replace('\\"', '"') - f = author.find('@') - return author[:f].replace('.', ' ') + return stringutil.person(author) @templatefilter('revescape') def revescape(text): diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py --- a/mercurial/utils/stringutil.py +++ b/mercurial/utils/stringutil.py @@ -308,3 +308,29 @@ False ''' return bool(_correctauthorformat.match(author)) + +def person(author): + """Any text. Returns the name before an email address, + interpreting it as per RFC 5322. + >>> person(b'foo@bar') + 'foo' + >>> person(b'Foo Bar ') + 'Foo Bar' + >>> person(b'"Foo Bar" ') + 'Foo Bar' + >>> person(b'"Foo \"buz\" Bar" ') + 'Foo "buz" Bar' + >>> # The following are invalid, but do exist in real-life + ... + >>> person(b'Foo "buz" Bar ') + 'Foo "buz" Bar' + >>> person(b'"Foo Bar ') + 'Foo Bar' + """ + if '@' not in author: + return author + f = author.find('<') + if f != -1: + return author[:f].strip(' "').replace('\\"', '"') + f = author.find('@') + return author[:f].replace('.', ' ')