WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#19808 closed defect (bug) (fixed)

PHPMailer -> MsgHTML single quote bug

Reported by: WPsites Owned by:
Milestone: 3.4 Priority: normal
Severity: minor Version: 3.3.1
Component: Mail Keywords: has-patch close
Focuses: Cc:

Description

If you pass in the contents of a HTML email to the MsgHTML method of the PHPMailer class it should attach all images to the email and replace the image src with the path to the attached image. If you use double quotes for the image src everything works fine.

<img src="image.png" />

If however you use single quotes (which as far as I'm aware is still part of the HTML spec for valid attributes) then the function doesn't replace any images or attach any of the images to the email like it's suppose to.

The problem is down to two regular expressions that require double quotes. I have created a diff patch to fix those regular expressions, making both single and double quotes valid.

So now both these work:

<img src="image.png" /> and <img src='image.png' />

I'm not sure what the protocol is regarding patches for external modules but thought I would mention the issue here. I have also sent the diff patch to the developer of the class as specified on Google code so if my patch is worthy (needed even) then the update might get into a future release of PHPMailer.

Attachments (2)

class-phpmailer.php.diff (1.2 KB) - added by WPsites 2 years ago.
Patch
class-phpmailer.php.v2.diff (1.2 KB) - added by WPsites 2 years ago.
New patch with pipe removed

Download all attachments as: .zip

Change History (6)

WPsites2 years ago

Patch

comment:1 WPsites2 years ago

  • Keywords has-patch added

comment:2 kurtpayne2 years ago

  • Cc kpayne@… added

Your code would also match: <img src=|image.png| />

The character group (square brackets) already means "any of these characters." You would only use the pipe in a parentheses group. For example: [\"'] is equivalent to (\"|')

Have you tested without the pipe?

Is it a problem that this could would also match imbalanced quotes? This matches:

<img src='image.png" /> and <img src="image.png' />

I would, generally, say no, since the images get re-written using correct markup. Others may want to weigh in on this.

Version 0, edited 2 years ago by kurtpayne (next)

WPsites2 years ago

New patch with pipe removed

comment:3 WPsites2 years ago

I have updated the patch to remove the pipe.

Well spotted, I'd like to think of the quote imbalance rewrite as a feature lol.

comment:4 kurtpayne2 years ago

  • Keywords close added
  • Milestone changed from Awaiting Review to 3.4
  • Resolution set to fixed
  • Status changed from new to closed

Ticket #19887 has upgraded the version of PHPMailer in WordPress to 5.2.1 which includes this patch.

Note: See TracTickets for help on using tickets.