From 12cead32f2d3065bf88fff77989aef58434f4212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 9 Oct 2013 15:38:21 +0200 Subject: [PATCH 1/2] MDL-41672 Add html2text unit test for multiple occurrences of the same URL --- lib/tests/html2text_test.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/tests/html2text_test.php b/lib/tests/html2text_test.php index a3f75c28b5d..ed88bb5004d 100644 --- a/lib/tests/html2text_test.php +++ b/lib/tests/html2text_test.php @@ -96,6 +96,20 @@ have been fixed last weekassertSame(1, preg_match('|^'.preg_quote('[2] http://another.url/?f=a&b=2').'$|m', $result)); $this->assertSame(1, preg_match('|^'.preg_quote('[3] http://third.url/view.php').'$|m', $result)); $this->assertSame(false, strpos($result, '[4]')); + + // Test multiple occurrences of the same URL. + $text = '

See moodle.org, + google, univ-lemans + and google. + Also try google via HTTPS.'; + $result = html_to_text($text, 5000, true); + $this->assertSame(0, strpos($result, 'See moodle.org [1], google [2], univ-lemans [3] and google [2]. Also try google via HTTPS [4].')); + $this->assertSame(false, strpos($result, '[0]')); + $this->assertSame(1, preg_match('|^'.preg_quote('[1] http://moodle.org').'$|m', $result)); + $this->assertSame(1, preg_match('|^'.preg_quote('[2] http://www.google.fr').'$|m', $result)); + $this->assertSame(1, preg_match('|^'.preg_quote('[3] http://www.univ-lemans.fr').'$|m', $result)); + $this->assertSame(1, preg_match('|^'.preg_quote('[4] https://www.google.fr').'$|m', $result)); + $this->assertSame(false, strpos($result, '[5]')); } /** From 11b4ad97f4b3a12b6aaf22223ce1834b3247003c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alain=20Corbi=C3=A8re?= Date: Wed, 9 Oct 2013 15:40:38 +0200 Subject: [PATCH 2/2] MDL-41672 Fix html2text processing of multiple occurrences of the same URL --- lib/html2text.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/html2text.php b/lib/html2text.php index f01ce8f8dd9..7b9eb296c8a 100644 --- a/lib/html2text.php +++ b/lib/html2text.php @@ -580,9 +580,14 @@ class html2text } if (($index = array_search($url, $this->_link_list)) === false) { + // Add the link to the list. $this->_link_list[] = $url; $index = count($this->_link_list); } + else { + // Use the index of the existing link in the list (we enumerate from 1, not from 0). + $index++; + } return $display . ' [' . ($index) . ']'; }