- 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
===========================
- 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 usage of non-standard HTTP error codes (#1487797)
- Improve performance by including files with absolute path (#1487849)

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

@ -607,6 +607,7 @@ function rcmail_wash_html($html, $p = array(), $cid_replaces)
$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);
}
// turn relative into absolute urls
$html = rcmail_resolve_base($html);
@ -955,13 +956,13 @@ function rcmail_message_headers($attrib, $headers=NULL)
function rcmail_message_full_headers($attrib, $headers=NULL)
{
global $OUTPUT;
$html = html::div(array('class' => "more-headers show-headers", 'onclick' => "return ".JS_OBJECT_NAME.".command('load-headers','',this)"), '');
$html .= html::div(array('id' => "all-headers", 'class' => "all", 'style' => 'display:none'), html::div(array('id' => 'headers-source'), ''));
$OUTPUT->add_gui_object('all_headers_row', 'all-headers');
$OUTPUT->add_gui_object('all_headers_box', 'headers-source');
return html::div($attrib, $html);
}
@ -1086,8 +1087,8 @@ function rcmail_resolve_base($body)
$replacer = new rcube_base_replacer($regs[2]);
// replace all relative paths
$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('/(src|background|href)=(["\']?)([^"\'\s]+)(\2|\s|>)/Ui', array($replacer, 'callback'), $body);
$body = preg_replace_callback('/(url\s*\()(["\']?)([^"\'\)\s]+)(\2)\)/Ui', array($replacer, 'callback'), $body);
}
return $body;

@ -145,4 +145,16 @@ class rcube_test_mailfunc extends UnitTestCase
$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