Automatically encode all email links using as hex HTML entities

It only encodes the `href`, not any content of the node.
This commit is contained in:
Jannik Zschiesche 2014-09-02 10:10:54 +02:00
parent 0220a93010
commit 9e0e0d86ad
2 changed files with 18 additions and 2 deletions

View File

@ -1135,7 +1135,7 @@ class Parsedown
'name' => 'a',
'text' => $matches[1],
'attributes' => array(
'href' => 'mailto:'.$matches[1],
'href' => $this->encodeEmailUrl('mailto:' . $matches[1]),
),
),
);
@ -1231,6 +1231,11 @@ class Parsedown
$url = str_replace(array('&', '<'), array('&amp;', '&lt;'), $Link['url']);
if ("mailto:" === substr($url, 0, 7))
{
$url = $this->encodeEmailUrl($url);
}
if ($Excerpt['text'][0] === '!')
{
$Element = array(
@ -1331,6 +1336,17 @@ class Parsedown
return $markup;
}
private function encodeEmailUrl ($email)
{
$encoded = '';
for ($x = 0, $_length = strlen($email); $x < $_length; $x ++) {
$encoded .= '&#x' . bin2hex($email[$x]) . ';';
}
return $encoded;
}
#
# Multiton
#

View File

@ -1 +1 @@
<p>my email is <a href="mailto:me@example.com">me@example.com</a></p>
<p>my email is <a href="&#x6d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#x3a;&#x6d;&#x65;&#x40;&#x65;&#x78;&#x61;&#x6d;&#x70;&#x6c;&#x65;&#x2e;&#x63;&#x6f;&#x6d;">me@example.com</a></p>