Fix so links over images are not removed in plain text signatures converted from HTML (#4473)

pull/5838/head
Aleksander Machniak 7 years ago
parent 6f87a32052
commit 21e7d873ce

@ -14,6 +14,7 @@ CHANGELOG Roundcube Webmail
- Allow contacts without an email address (#5079)
- Localized timezone selector (#4983)
- Use 7bit encoding for ISO-2022-* charsets in sent mail (#5640)
- Fix so links over images are not removed in plain text signatures converted from HTML (#4473)
- Fix various issues when downloading files with names containing non-ascii chars, use RFC 2231 (#5772)
- Password: Fix compatibility with PHP 7+ in cpanel_webmail driver (#5820)
- Fix decoding non-ascii attachment names from TNEF attachments (#5646, #5799)

@ -517,7 +517,7 @@ class rcube_html2text
*/
protected function _build_link_list($link, $display)
{
if (!$this->_do_links || empty($link)) {
if (empty($link)) {
return $display;
}
@ -542,6 +542,19 @@ class rcube_html2text
$url .= "$link";
}
if (!$this->_do_links) {
// When not using link list use URL if there's no content (#5795)
// The content here is HTML, convert it to text first
$h2t = new rcube_html2text($display, false, false, 1024, $this->charset);
$display = $h2t->get_text();
if (empty($display) && preg_match('!^([a-z][a-z0-9.+-]+://)!i', $link)) {
return $link;
}
return $display;
}
if (($index = array_search($url, $this->_link_list)) === false) {
$index = count($this->_link_list);
$this->_link_list[] = $url;

@ -143,4 +143,39 @@ Links:
$this->assertSame($expected, $res, 'Skip link with href == content');
}
/**
* Test <a> links handling when not using link list (#5795)
*
* @dataProvider data_links_no_list
*/
function test_links_no_list($input, $output)
{
$h2t = new rcube_html2text($input, false, false);
$res = $h2t->get_text();
$this->assertSame($output, $res, 'Links handling');
}
function data_links_no_list()
{
return array(
array(
'this is <a href="http://test.com">content</a>',
'this is content',
),
array(
'this is <a href="#test">content&amp;&nbsp;test</a>',
'this is content& test',
),
array(
'this is <a href="">content</a>',
'this is content',
),
array(
'this is <a href="http://test.com"><img src=http://test.com/image" alt="image" /></a>',
'this is http://test.com',
),
);
}
}

Loading…
Cancel
Save