1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Merge pull request #566 from aidantwoods/fix/email-autolink

Email autolink shouldn't be started by HTML tags
This commit is contained in:
Aidan Woods 2018-03-10 00:06:59 +00:00 committed by GitHub
commit aac00ac742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -1142,8 +1142,14 @@ class Parsedown
protected function inlineEmailTag($Excerpt)
{
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
{
$hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?';
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
if (strpos($Excerpt['text'], '>') !== false
and preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches)
){
$url = $matches[1];
if ( ! isset($matches[2]))
@ -1479,7 +1485,7 @@ class Parsedown
{
$markup .= '>';
if (!isset($Element['nonNestables']))
if (!isset($Element['nonNestables']))
{
$Element['nonNestables'] = array();
}

View File

@ -1 +1,2 @@
<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>
<p>html tags shouldn't start an email autolink <strong>first.last@example.com</strong></p>

View File

@ -1 +1,3 @@
my email is <me@example.com>
my email is <me@example.com>
html tags shouldn't start an email autolink <strong>first.last@example.com</strong>