\Nette\Mail\Message – too strict regex for image embedding?

Notice: This thread is very old.
JirkaChadima
Member | 5
+
0
-

Hi, today I came across a possible bug in \Nette\Mail\Message. It is related to a regex that takes care of embedding images directly into a message. Regex does not work in one particular case that I (and many e-mail clients and browsers) consider valid such as:

<div style="background: url(image.png)"></div> <!-- no apostrophes around image.png -->

This works as expected (image.png is embedded):

<div style="background: url('image.png')"></div> <!-- apostrophes around image.png -->

I believe the regex should also match relative image path in url without apostrophes.

Is this a bug or a desired behaviour that forces users to be strict about their CSS markup? Do you guys know any low-level workaround? I do not have direct control over the source markup (although preprocessing is possible, it is not desirable). Thank you.

Regex I am talking about:

<?php
// https://api.nette.org/nette/2.1/source-Mail.Message.php.html#241
$matches = Strings::matchAll(
    $html,
    '#(src\s*=\s*|background\s*=\s*|url\()(["\'])(?![a-z]+:|[/\\#])(.+?)\\2#i',
    PREG_OFFSET_CAPTURE
);
?>

Testing ground: http://regex101.com/r/nY7iR9

David Grudl
Nette Core | 8082
+
0
-

Can you send pull request with test to Github?