Fix malformed characters in HTML message with charset meta tag not in head (#7116)

pull/7135/head
Aleksander Machniak 5 years ago
parent 5f30dc68a3
commit 37cfa0a43b

@ -31,6 +31,7 @@ CHANGELOG Roundcube Webmail
- Fix bug where 'text' attribute on body tag was ignored when displaying HTML message (#7109)
- Fix bug where next message wasn't displayed after delete in List mode (#7096)
- Fix so number of contacts in a group is not limited to 200 when redirecting to mail composer from Contacts (#6972)
- Fix malformed characters in HTML message with charset meta tag not in head (#7116)
RELEASE 1.4.1
-------------

@ -839,12 +839,10 @@ function rcmail_wash_html($html, $p, $cid_replaces = array())
// washtml's DOMDocument methods cannot work without that
$meta = '<meta charset="'.RCUBE_CHARSET.'" />';
// remove old meta tag and add the new one, making sure
// that it is placed in the head (#1488093)
$html = preg_replace('/<meta[^>]+charset=[a-z0-9_"-]+[^>]*>/Ui', $meta, $html, -1, $rcount);
if (!$rcount) {
$html = preg_replace('/(<head[^>]*>)/Ui', '\\1'.$meta, $html, -1, $rcount);
}
// remove old meta tag and add the new one, making sure that it is placed in the head (#3510, #7116)
$html = preg_replace('/<meta[^>]+charset=[a-z0-9_"-]+[^>]*>/Ui', '', $html, -1);
$html = preg_replace('/(<head[^>]*>)/Ui', '\\1'.$meta, $html, -1, $rcount);
if (!$rcount) {
// Note: HTML without <html> tag may still be a valid input (#6713)
if (($pos = stripos($html, '<html')) === false) {

@ -172,6 +172,11 @@ class MailFunc extends PHPUnit_Framework_TestCase
$body = '<html><head></head>Test1<br>Test2';
$washed = rcmail_wash_html($body, $args);
$this->assertTrue(strpos($washed, "<html><head>$meta</head>") === 0, "Meta tag insertion (5)");
$body = '<html><head></head><body>Test1<br>Test2<meta charset="utf-8"></body>';
$washed = rcmail_wash_html($body, $args);
$this->assertTrue(strpos($washed, "<html><head>$meta</head>") === 0, "Meta tag insertion (6)");
$this->assertTrue(strpos($washed, "Test2</body>") > 0, "Meta tag insertion (7)");
}
/**

Loading…
Cancel
Save