Skip to content

Commit bb9e0de

Browse files
authored
Merge pull request #173 from w3c/obfuscate-emails
Obfuscate email addresses, similarly to what's done on lists.w3.org
2 parents b8c428d + 04d94f9 commit bb9e0de

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/Twig/TwigExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function getFilters()
7272
new TwigFilter('strip_group_type', [$this, 'stripGroupType']),
7373
new TwigFilter('locale_to_bcp47', [$this, 'localeToBcp47']),
7474
new TwigFilter('bcp47_to_locale', [$this, 'bcp47ToLocale']),
75+
new TwigFilter('obfuscate', [$this, 'obfuscate'], ['is_safe' => ['html']]),
7576
];
7677
}
7778

@@ -291,4 +292,10 @@ public function bcp47ToLocale(string $locale): string
291292
{
292293
return str_replace('-', '_', $locale);
293294
}
295+
296+
public function obfuscate(string $text): string
297+
{
298+
// Obfuscate string by replacing all characters with their HTML entity equivalents
299+
return mb_encode_numericentity($text, [0x000000, 0x10ffff, 0, 0xffffff], 'UTF-8');
300+
}
294301
}

templates/components/evangelists.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<p>{{ 'components.people.tel'|trans({'number': evangelist.phone}, 'w3c_website_templates_bundle')|raw }}</p>
3030
{% endif %}
3131
{% if evangelist.email %}
32-
<p>{{ 'components.people.email'|trans({'email': evangelist.email}, 'w3c_website_templates_bundle')|raw }}</p>
32+
<p>{{ 'components.people.email'|trans({'email': evangelist.email|obfuscate}, 'w3c_website_templates_bundle')|raw }}</p>
3333
{% endif %}
3434
</div>
3535
</div>

templates/components/listings/people/user.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
<div>
2121
{% block email %}
2222
<div>
23-
<a href="mailto:{{ user.preferredEmail }}" class="with-icon--before">
23+
<a href="mailto:{{ user.preferredEmail|obfuscate }}" class="with-icon--before">
2424
<img class="icon" src="{{ asset('svg/envelope.svg', 'website-2021') }}"
2525
width="20"
2626
height="20"
2727
alt aria-hidden="true"/>
28-
{{ user.preferredEmail }}
28+
{{ user.preferredEmail|obfuscate }}
2929
</a>
3030
</div>
3131
{% endblock %}

0 commit comments

Comments
 (0)