Skip to content
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

Craft 2.6 bug: Emailed URLs get mangled due to Markdown parsing bug #1800

Closed
SimonEast opened this issue Jun 28, 2017 · 2 comments
Closed

Craft 2.6 bug: Emailed URLs get mangled due to Markdown parsing bug #1800

SimonEast opened this issue Jun 28, 2017 · 2 comments
Assignees
Labels

Comments

@SimonEast
Copy link

In Craft 2.6, when sending a plaintext email that contains underscores, these are often converted to <em> tags which can mangle and break URLs.

$email = new EmailModel();
$email->toEmail = '...';
$email->subject = '...';
$email->body = 'Visit http://example.com/special_link_here';
craft()->email->sendEmail($email);

Unfortunately the resulting body of the email is mangled and appears like this:

<p>Visit http://example.com/special<em>link</em>here</p>

It seems to be due to faulty parsing by the Markdown library (is this library part of Yii? I'm not sure). Apparently the Craft team may have come across this bug before, since there is a comment in app/Controllers/TemplatesController.php line 202 that says:

// Escape any inner-word underscores, which Markdown mistakes for italics
// TODO: This won't be necessary in 3.0 thanks to Parsedown
$variables['message'] = preg_replace('/(?<=[a-zA-Z])_(?=[a-zA-Z])/', '\_', $variables['message']);

Unfortunately this workaround is not applied in EmailService so the issue persists.

This can also break Craft links such as craft()->users->getPasswordResetUrl($user) which appear to sometimes contain underscores.

Although there are a couple of workarounds below, developers are unlikely to expect this behaviour, so perhaps a workaround is needed until such point that the Markdown library is updated/replaced.

Workarounds

  1. Wrap URL in <angle brackets>. This tells Markdown to render a clickable link, and not treat it as plain text.

  2. Provide an HTML version of the email message. This prevents the Markdown-to-HTML conversion

Unfortunately there's currently no way to ask Craft to send plaintext only, see issue #1107.

Additional info

  • Craft version: 2.6.2981
  • PHP version: 5.6.30
  • Database driver & version:
@angrybrad angrybrad self-assigned this Jun 28, 2017
@angrybrad angrybrad added the bug label Jun 28, 2017
@angrybrad
Copy link
Member

Thanks, Simon... fixed for the next release!

@SimonEast
Copy link
Author

Wow, that was super blazingly amazingly fast. Bug fixed in 25mins! Thanks so much Brad!

brandonkelly added a commit that referenced this issue Jun 30, 2017
brandonkelly added a commit that referenced this issue Feb 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants