[damned-lies] Obfuscate email addresses on about page (#682680)
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Obfuscate email addresses on about page (#682680)
- Date: Wed, 13 Mar 2013 14:23:23 +0000 (UTC)
commit a3aa061a8f2e677f0d1a0870b019754709686802
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Mar 13 15:21:42 2013 +0100
Obfuscate email addresses on about page (#682680)
Thanks Chandan Kumar for the initial patch and the review.
common/views.py | 4 ++--
people/models.py | 11 +++++++----
people/tests/__init__.py | 20 +++++++++++++++++++-
3 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/common/views.py b/common/views.py
index 618ea16..3fe5c8c 100644
--- a/common/views.py
+++ b/common/views.py
@@ -27,7 +27,7 @@ from django.shortcuts import render
from django.template.loader import get_template, TemplateDoesNotExist
from django.utils.translation import ugettext as _
-from people.models import Person
+from people.models import Person, obfuscate_email
from teams.models import Role
from people.forms import RegistrationForm
from common.utils import get_user_locale
@@ -47,7 +47,7 @@ def about(request):
if translator_credits == "translator-credits":
translator_credits = ''
else:
- translator_credits = translator_credits.split('\n')
+ translator_credits = [obfuscate_email(line) for line in translator_credits.split('\n')]
context = {
'pageSection': 'home',
'translator_credits': translator_credits,
diff --git a/people/models.py b/people/models.py
index 0b81054..a6a7585 100644
--- a/people/models.py
+++ b/people/models.py
@@ -20,15 +20,18 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import datetime
+import re
from django.db import models
+from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User, UserManager
def obfuscate_email(email):
if email:
- data = email.replace('@', ' at ').replace('.', ' dot ')
- return data.replace(' ', ' ')
+ # Do not replace the 1st dot in "First M. Name <name dom com>"
+ email = re.sub(r'(\w)\.(\w)', r'\1 dot \2', email)
+ return mark_safe(escape(email.replace('@', ' at ')).replace(' ', ' '))
return ''
class Person(User):
@@ -109,10 +112,10 @@ class Person(User):
self.save()
def no_spam_email(self):
- return mark_safe(obfuscate_email(self.email))
+ return obfuscate_email(self.email)
def no_spam_bugzilla_account(self):
- return mark_safe(obfuscate_email(self.bugzilla_account))
+ return obfuscate_email(self.bugzilla_account)
@property
def name(self):
diff --git a/people/tests/__init__.py b/people/tests/__init__.py
index 905c415..55f8fd2 100644
--- a/people/tests/__init__.py
+++ b/people/tests/__init__.py
@@ -22,8 +22,9 @@ import datetime
from django.test import TestCase
from django.core.urlresolvers import reverse
+from django.utils.safestring import SafeData
-from people.models import Person
+from people.models import Person, obfuscate_email
from people import forms
class PeopleTestCase(TestCase):
@@ -93,3 +94,20 @@ class PeopleTestCase(TestCase):
Person.clean_obsolete_accounts()
self.assertEqual(Person.objects.all().count(), 4)
self.assertEqual(set(Person.objects.all()), set([p1, p2, p3, p4]))
+
+ def test_obfuscate_email(self):
+ self.assertEqual(obfuscate_email(''), '')
+ self.assertEqual(
+ obfuscate_email('me company domain org'),
+ 'me dot company at domain dot org'
+ )
+ self.assertIsInstance(obfuscate_email('me company domain org'), SafeData)
+ self.assertEqual(
+ obfuscate_email('George P. McLain <george domain org'),
+ 'George P. McLain <george at domain dot org'
+ )
+ self.assertEqual(
+ obfuscate_email('Me <me company domain org>\nYou <some-address example com>'),
+ 'Me <me dot company at domain dot org>\n'
+ 'You <some-address at example dot com>'
+ )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]