mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
Merge branch 'MDL-38698-master' of git://github.com/FMCorz/moodle
This commit is contained in:
commit
5be3d8d329
@ -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 = "(?<!=[\"'])$urlstart((?:$domainsegment\.)+$domainsegment|$numericip)" .
|
||||
"($port?$path$querystring?$fragment?)(?<![]),.;])";
|
||||
// Lookbehind assertions.
|
||||
// Is not HTML attribute or CSS URL property. Unfortunately legit text like "url(http://...)" will not be a link.
|
||||
$lookbehindstart = "(?<!=[\"']|\burl\([\"' ]|\burl\()";
|
||||
$lookbehindend = "(?<![]),.;])";
|
||||
|
||||
$regex = "$lookbehindstart$urlstart((?:$domainsegment\.)+$domainsegment|$numericip)" .
|
||||
"($port?$path$querystring?$fragment?)$lookbehindend";
|
||||
if ($unicoderegexp) {
|
||||
$regex = '#' . $regex . '#ui';
|
||||
} else {
|
||||
|
@ -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<a href="$2://$3$4" target="_blank">$2://$3$4</a>', $text);
|
||||
/// eg www.moodle.com
|
||||
$text = preg_replace("%([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])%i",
|
||||
'$1<a href="http://www.$2$3" target="_blank">www.$2$3</a>', $text);
|
||||
}
|
||||
|
||||
function get_convert_urls_into_links_test_cases() {
|
||||
$texts = array (
|
||||
//just a url
|
||||
@ -144,6 +131,11 @@ class filter_urltolink_testcase extends basic_testcase {
|
||||
'<td background="www.moodle.org"> </td>' => '<td background="www.moodle.org"> </td>',
|
||||
'<form name="input" action="http://moodle.org/submit.asp" method="get">'=>'<form name="input" action="http://moodle.org/submit.asp" method="get">',
|
||||
'<td background="https://www.moodle.org"> </td>' => '<td background="https://www.moodle.org"> </td>',
|
||||
// CSS URLs.
|
||||
'<table style="background-image: url(\'http://moodle.org/pic.jpg\');">' => '<table style="background-image: url(\'http://moodle.org/pic.jpg\');">',
|
||||
'<table style="background-image: url(http://moodle.org/pic.jpg);">' => '<table style="background-image: url(http://moodle.org/pic.jpg);">',
|
||||
'<table style="background-image: url("http://moodle.org/pic.jpg");">' => '<table style="background-image: url("http://moodle.org/pic.jpg");">',
|
||||
'<table style="background-image: url( http://moodle.org/pic.jpg );">' => '<table style="background-image: url( http://moodle.org/pic.jpg );">',
|
||||
//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
|
||||
@ -181,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)');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user