-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Email autolink shouldn't be started by HTML tags #566
Conversation
The regex looks a bit huge, but it isn't very complex (the majority is defining character classes), so I don't think it'll be any (much?) worse than the existing regex complexity (open to performance suggestions though, cc: @PhrozenByte) I think |
a3755b5
to
19f1bb9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex was taken from CommonMark, right? It is stricter than I'd write it myself, but since we're trying to be compatible with CommonMark we should use it anyway.
Looks great! 👍
Parsedown.php
Outdated
@@ -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]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just making the regex a little easier to read:
$hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?';
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@' . $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
Yup, (though they ripped it straight out the HTML5 spec ;p). The only changes I made were escaping a |
Alright. Yeah, no backtracking necessary there. |
Thanks @PhrozenByte for the suggestion :)
Fixes #565