- Fix relative URLs handling according to a <base> in HTML (#1487889)

release-0.6
alecpl 14 years ago
parent 09b0e36b3f
commit c08b18c4b9

@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail CHANGELOG Roundcube Webmail
=========================== ===========================
- Fix relative URLs handling according to a <base> in HTML (#1487889)
- Fix handling of top-level domains with more than 5 chars or unicode chars (#1487883) - Fix handling of top-level domains with more than 5 chars or unicode chars (#1487883)
- Fix usage of non-standard HTTP error codes (#1487797) - Fix usage of non-standard HTTP error codes (#1487797)
- Improve performance by including files with absolute path (#1487849) - Improve performance by including files with absolute path (#1487849)

@ -231,7 +231,7 @@ function make_absolute_url($path, $base_url)
} }
// $path is absolute // $path is absolute
if ($path{0}=='/') if ($path[0] == '/')
$abs_path = $host_url.$path; $abs_path = $host_url.$path;
else else
{ {

@ -607,6 +607,7 @@ function rcmail_wash_html($html, $p = array(), $cid_replaces)
$html = '<head></head>'. $html; $html = '<head></head>'. $html;
$html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '<head>')+6), 0); $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '<head>')+6), 0);
} }
// turn relative into absolute urls // turn relative into absolute urls
$html = rcmail_resolve_base($html); $html = rcmail_resolve_base($html);
@ -1086,8 +1087,8 @@ function rcmail_resolve_base($body)
$replacer = new rcube_base_replacer($regs[2]); $replacer = new rcube_base_replacer($regs[2]);
// replace all relative paths // replace all relative paths
$body = preg_replace_callback('/(src|background|href)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Ui', array($replacer, 'callback'), $body); $body = preg_replace_callback('/(src|background|href)=(["\']?)([^"\'\s]+)(\2|\s|>)/Ui', array($replacer, 'callback'), $body);
$body = preg_replace_callback('/(url\s*\()(["\']?)([\.\/]+[^"\'\)\s]+)(\2)\)/Ui', array($replacer, 'callback'), $body); $body = preg_replace_callback('/(url\s*\()(["\']?)([^"\'\)\s]+)(\2)\)/Ui', array($replacer, 'callback'), $body);
} }
return $body; return $body;

@ -145,4 +145,16 @@ class rcube_test_mailfunc extends UnitTestCase
$this->assertNoPattern('|<p>test2</p>|', $washed, "Conditional HTML comments"); $this->assertNoPattern('|<p>test2</p>|', $washed, "Conditional HTML comments");
} }
/**
* Test URI base resolving in HTML messages
*/
function test_resolve_base()
{
$html = file_get_contents(TESTS_DIR . 'src/htmlbase.txt');
$html = rcmail_resolve_base($html);
$this->assertPattern('|src="http://alec\.pl/dir/img1\.gif"|', $html, "URI base resolving [1]");
$this->assertPattern('|src="http://alec\.pl/dir/img2\.gif"|', $html, "URI base resolving [2]");
$this->assertPattern('|src="http://alec\.pl/img3\.gif"|', $html, "URI base resolving [3]");
}
} }

@ -0,0 +1,10 @@
<html>
<head>
<base href="http://alec.pl/dir/" />
</head>
<body>
<img src="img1.gif" />
<img src="./img2.gif" />
<img src="../img3.gif" />
</body>
</html>
Loading…
Cancel
Save