mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-20 03:51:29 +02:00
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:
parent
0220a93010
commit
9e0e0d86ad
@ -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('&', '<'), $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
|
||||
#
|
||||
|
@ -1 +1 @@
|
||||
<p>my email is <a href="mailto:me@example.com">me@example.com</a></p>
|
||||
<p>my email is <a href="mailto:me@example.com">me@example.com</a></p>
|
Loading…
Reference in New Issue
Block a user