From ff406834043d4213b9682c2c941ec2952e9783f7 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 17 Jun 2015 09:30:44 +0200 Subject: [PATCH] Fix so links with href == content aren't added to links list on html to text conversion (#1490434) --- CHANGELOG | 1 + program/lib/Roundcube/rcube_html2text.php | 7 ++++++- tests/Framework/Html2text.php | 25 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 90f4d3439..c6db1004c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ CHANGELOG Roundcube Webmail - Fix unintentional messages list page change on page switch in compose addressbook (#1490427) - Fix race-condition in saving user preferences and loading plugin config (#1490431) - Fix so plain text signature field uses monospace font (#1490435) +- Fix so links with href == content aren't added to links list on html to text conversion (#1490434) RELEASE 1.1.2 ------------- diff --git a/program/lib/Roundcube/rcube_html2text.php b/program/lib/Roundcube/rcube_html2text.php index 15dc2b59a..5e12524b6 100644 --- a/program/lib/Roundcube/rcube_html2text.php +++ b/program/lib/Roundcube/rcube_html2text.php @@ -509,7 +509,7 @@ class rcube_html2text * @param string $link URL of the link * @param string $display Part of the text to associate number with */ - protected function _build_link_list( $link, $display ) + protected function _build_link_list($link, $display) { if (!$this->_do_links || empty($link)) { return $display; @@ -520,6 +520,11 @@ class rcube_html2text return $display; } + // skip links with href == content (#1490434) + if ($link === $display) { + return $display; + } + if (preg_match('!^([a-z][a-z0-9.+-]+:)!i', $link)) { $url = $link; } diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php index dee767057..2f2459479 100644 --- a/tests/Framework/Html2text.php +++ b/tests/Framework/Html2text.php @@ -113,4 +113,29 @@ EOF; $this->assertContains('QUOTED TEXT INNER 1 INNER 2 NO END', $res, 'No quoating on invalid html'); } + + function test_links() + { + $html = 'content'; + $expected = 'content [1] + +Links: +------ +[1] http://test.com +'; + + $ht = new rcube_html2text($html, false, true); + $res = $ht->get_text(); + + $this->assertSame($expected, $res, 'Links list'); + + // href == content (#1490434) + $html = 'http://test.com'; + $expected = 'http://test.com'; + + $ht = new rcube_html2text($html, false, true); + $res = $ht->get_text(); + + $this->assertSame($expected, $res, 'Skip link with href == content'); + } }