Skip to content

Commit

Permalink
Fix #565 by validating email as defined in commonmark spec
Browse files Browse the repository at this point in the history
  • Loading branch information
aidantwoods committed Mar 9, 2018
1 parent f70d964 commit 721b885
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -1142,8 +1142,14 @@ protected function inlineCode($Excerpt)

protected function inlineEmailTag($Excerpt)
{
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
{
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9]'
.'(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'
.'(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*'
;

if (strpos($Excerpt['text'], '>') !== false
and preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches)
){
$url = $matches[1];

if ( ! isset($matches[2]))
Expand Down Expand Up @@ -1479,7 +1485,7 @@ protected function element(array $Element)
{
$markup .= '>';

if (!isset($Element['nonNestables']))
if (!isset($Element['nonNestables']))
{
$Element['nonNestables'] = array();
}
Expand Down

0 comments on commit 721b885

Please sign in to comment.