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