From e15878798a7b2eb17846414c25dd6b61fc853b57 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 12 Dec 2013 11:31:51 +0100 Subject: [PATCH 1/2] MDL-38698 filter_urltolink: Do not link the URL property of CSS --- filter/urltolink/filter.php | 9 +++++++-- filter/urltolink/tests/filter_test.php | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/filter/urltolink/filter.php b/filter/urltolink/filter.php index 290e7ed3cdf..538d03e8e4f 100644 --- a/filter/urltolink/filter.php +++ b/filter/urltolink/filter.php @@ -132,8 +132,13 @@ class filter_urltolink extends moodle_text_filter { $querystring = '(?:\?(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'; $fragment = '(?:\#(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)'; - $regex = "(? ' => ' ', '
'=>'', ' ' => ' ', + // CSS URLs. + '' => '
', + '
' => '
', + '
' => '
', + '
' => '
', //partially escaped img tag 'partially escaped img tag <img src="http://moodle.org/logo/logo-240x60.gif" />' => 'partially escaped img tag <img src="http://moodle.org/logo/logo-240x60.gif" />', //fully escaped img tag. Commented out as part of MDL-21183 From 850db41832241838dcf7aada54fcfca97b74b8e1 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 17 Dec 2013 07:03:02 +0100 Subject: [PATCH 2/2] MDL-38698 filter_urltolink: Remove performance test in Unit Test --- filter/urltolink/tests/filter_test.php | 39 -------------------------- 1 file changed, 39 deletions(-) diff --git a/filter/urltolink/tests/filter_test.php b/filter/urltolink/tests/filter_test.php index 2a3842ca2d6..58bd4a3528d 100644 --- a/filter/urltolink/tests/filter_test.php +++ b/filter/urltolink/tests/filter_test.php @@ -31,19 +31,6 @@ require_once($CFG->dirroot . '/filter/urltolink/filter.php'); // Include the cod class filter_urltolink_testcase extends basic_testcase { - /** - * Helper function that represents the legacy implementation - * of convert_urls_into_links() - */ - protected function old_convert_urls_into_links(&$text) { - /// Make lone URLs into links. eg http://moodle.com/ - $text = preg_replace("%([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])%i", - '$1$2://$3$4', $text); - /// eg www.moodle.com - $text = preg_replace("%([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])%i", - '$1www.$2$3', $text); - } - function get_convert_urls_into_links_test_cases() { $texts = array ( //just a url @@ -186,32 +173,6 @@ class filter_urltolink_testcase extends basic_testcase { $this->assertEquals($correctresult, $text); } - function test_convert_urls_into_links_performance() { - $testablefilter = new testable_filter_urltolink(); - - $reps = 1000; - $text = file_get_contents(__DIR__ . '/fixtures/sample.txt'); - $time_start = microtime(true); - for($i=0;$i<$reps;$i++) { - $testablefilter->convert_urls_into_links($text); - } - $time_end = microtime(true); - $new_time = $time_end - $time_start; - - $time_start = microtime(true); - for($i=0;$i<$reps;$i++) { - $this->old_convert_urls_into_links($text); - } - $time_end = microtime(true); - $old_time = $time_end - $time_start; - - $fast_enough = false; - if( $new_time < $old_time ) { - $fast_enough = true; - } - - $this->assertEquals($fast_enough, true, 'Timing test: ' . $new_time . 'secs (new) < ' . $old_time . 'secs (old)'); - } }