Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templatefilters.py @ 16235:eb39bbda167b
templates/filters: strip quotes from {author|person}
RFC5322 (Internet Message Format) [0] says that the 'display name' of
an internet address [1] (what Mercurial calls 'person') can be quoted
with DQUOTE (ASCII 34: ") if it contains non-atom characters [2].
For example, dot '.' is a non-atom character. Also, DQUOTEs in a
quoted string will be escaped using "\" [2][3].
The current {author|person} template+filter just extracts the part
before an email address as-is. This can look ugly, especially on the
web interface, or when generating output for post-processing...
Moreover, as an example, the Mercurial repository has a bunch of
incoherent uses of DQUOTES in author names. As per Matt's digging:
$ hg log --template "{author|person}\n" | grep '"' | sort | uniq
"Andrei Vermel
"Aurelien Jacobs
"Daniel Santa Cruz
"Hidetaka Iwai
"Hiroshi Funai"
"Mathieu Clabaut
"Paul Moore
"Peter Arrenbrecht"
"Rafael Villar Burke
"Shun-ichi GOTO"
"Wallace, Eric S"
"Yann E. MORIN"
Josef "Jeff" Sipek
Radoslaw "AstralStorm" Szkodzinski
Fix the 'person' filter to remove leading and trailing DQUOTES,
and unescape remaining DQUOTES.
Given this author: "J. \"random\" DOE" <john@doe.net>
before: {author|person} : "J. \"random\" DOE"
after: {author|person} : J. "random" DOE
For the Mercurial repository, that leaves us with two authors with
DQUOTES, in acceptable positions:
$ hg log --template "{author|person}\n" | grep '"' | sort | uniq
Josef "Jeff" Sipek
Radoslaw "AstralStorm" Szkodzinski
[0] https://tools.ietf.org/html/rfc5322
[1] https://tools.ietf.org/html/rfc5322#section-3.4
[2] https://tools.ietf.org/html/rfc5322#section-3.2.4
[3] https://tools.ietf.org/html/rfc5322#section-3.2.1
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
author | "Yann E. MORIN" <yann.morin.1998@free.fr> |
---|---|
date | Tue, 06 Mar 2012 23:23:30 +0100 |
parents | f4a8d754cd0a |
children | db68ee3289b6 |
comparison
equal
deleted
inserted
replaced
16234:a6941d7033fa | 16235:eb39bbda167b |
---|---|
240 if "x" in flags: | 240 if "x" in flags: |
241 return "-rwxr-xr-x" | 241 return "-rwxr-xr-x" |
242 return "-rw-r--r--" | 242 return "-rw-r--r--" |
243 | 243 |
244 def person(author): | 244 def person(author): |
245 """:person: Any text. Returns the text before an email address.""" | 245 """:person: Any text. Returns the name before an email address, |
246 interpreting it as per RFC 5322. | |
247 """ | |
246 if not '@' in author: | 248 if not '@' in author: |
247 return author | 249 return author |
248 f = author.find('<') | 250 f = author.find('<') |
249 if f != -1: | 251 if f != -1: |
250 return author[:f].rstrip() | 252 return author[:f].strip(' "').replace('\\"', '"') |
251 f = author.find('@') | 253 f = author.find('@') |
252 return author[:f].replace('.', ' ') | 254 return author[:f].replace('.', ' ') |
253 | 255 |
254 def rfc3339date(text): | 256 def rfc3339date(text): |
255 """:rfc3339date: Date. Returns a date using the Internet date format | 257 """:rfc3339date: Date. Returns a date using the Internet date format |