Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#19808 closed defect (bug) (fixed)

PHPMailer -> MsgHTML single quote bug

Reported by: wpsites's profile 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 12 years ago.
Patch
class-phpmailer.php.v2.diff (1.2 KB) - added by WPsites 12 years ago.
New patch with pipe removed

Download all attachments as: .zip

Change History (6)

@WPsites
12 years ago

Patch

#1 @WPsites
12 years ago

  • Keywords has-patch added

#2 @kurtpayne
12 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 not a problem, since the images get re-written using correct markup. Others may want to weigh in on this.

Last edited 12 years ago by kurtpayne (previous) (diff)

@WPsites
12 years ago

New patch with pipe removed

#3 @WPsites
12 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.

#4 @kurtpayne
12 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.