email obfuscation on add-on detail pages (bug 556467)
This commit is contained in:
Родитель
1ffd905c10
Коммит
2b1820240b
|
@ -282,8 +282,8 @@
|
|||
</li>
|
||||
{% endif %}
|
||||
{% if addon.support_email %}
|
||||
<li><a href="mailto:{{ addon.support_email }}">{{
|
||||
_('E-mail your question') }}</a></li>
|
||||
<li>{{ emaillink(addon.support_email.localized_string,
|
||||
_('E-mail your question')) }}</li>
|
||||
{% endif %}
|
||||
{% if addon.support_url %}
|
||||
<li><a href="{{ addon.support_url|external_url }}">{{
|
||||
|
|
|
@ -6,8 +6,8 @@ from jingo import register, env
|
|||
from tower import ugettext as _
|
||||
|
||||
|
||||
@register.filter
|
||||
def emaillink(email):
|
||||
@register.function
|
||||
def emaillink(email, title=None):
|
||||
if not email:
|
||||
return ""
|
||||
|
||||
|
@ -20,7 +20,13 @@ def emaillink(email):
|
|||
# replace @ and .
|
||||
fallback = fallback.replace('@', '@').replace('.', '.')
|
||||
|
||||
node = u'<span class="emaillink">%s</span>' % fallback
|
||||
if title:
|
||||
title = jinja2.escape(title)
|
||||
else:
|
||||
title = '<span class="emaillink">%s</span>' % fallback
|
||||
|
||||
node = u'<a href="#">%s</a><span class="emaillink js-hidden">%s</span>' % (
|
||||
title, fallback)
|
||||
return jinja2.Markup(node)
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
{% if not profile.emailhidden %}
|
||||
<tr>
|
||||
<th>{{ _('Email address') }}</th>
|
||||
<td>{{ profile.email|emaillink }}</td>
|
||||
<td>{{ emaillink(profile.email) }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
|
|
|
@ -13,11 +13,22 @@ def test_emaillink():
|
|||
obfuscated = unicode(emaillink(email))
|
||||
|
||||
# remove junk
|
||||
m = re.match(r'<span class="emaillink">(.*?)<span class="i">null</span>'
|
||||
'(.*)</span>', obfuscated)
|
||||
m = re.match(r'<a href="#"><span class="emaillink">(.*?)'
|
||||
'<span class="i">null</span>(.*)</span></a>'
|
||||
'<span class="emaillink js-hidden">(.*?)'
|
||||
'<span class="i">null</span>(.*)</span>', obfuscated)
|
||||
obfuscated = (''.join((m.group(1), m.group(2)))
|
||||
.replace('@', '@').replace('.', '.'))[::-1]
|
||||
eq_(email, obfuscated)
|
||||
|
||||
title = 'E-mail your question'
|
||||
obfuscated = unicode(emaillink(email, title))
|
||||
m = re.match(r'<a href="#">(.*)</a>'
|
||||
'<span class="emaillink js-hidden">(.*?)'
|
||||
'<span class="i">null</span>(.*)</span>', obfuscated)
|
||||
eq_(title, m.group(1))
|
||||
obfuscated = (''.join((m.group(2), m.group(3)))
|
||||
.replace('@', '@').replace('.', '.'))[::-1]
|
||||
eq_(email, obfuscated)
|
||||
|
||||
|
||||
|
|
|
@ -19,10 +19,8 @@ $(document).ready(function(){
|
|||
// Initialize email links
|
||||
$('span.emaillink').each(function() {
|
||||
$(this).find('.i').remove();
|
||||
em = $(this).text().split('').reverse().join('');
|
||||
a = $('<a>').attr('href', 'mailto:' + em)
|
||||
.text(em);
|
||||
$(this).replaceWith(a);
|
||||
var em = $(this).text().split('').reverse().join('');
|
||||
$(this).prev('a').attr('href', 'mailto:' + em);
|
||||
});
|
||||
|
||||
// Set up input placeholders.
|
||||
|
|
Загрузка…
Ссылка в новой задаче