Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-40633 filter_urltolink breaking some image links.

This was a regression caused by MDL-22390. HTML like
<img src="http://www.example.com/logo.gif" />
was being broken.
  • Loading branch information...
commit 9bf7f1083404519de56e3764e47596f13a663b59 1 parent f830a2d
@timhunt timhunt authored
View
3  filter/urltolink/filter.php
@@ -123,6 +123,7 @@ protected function convert_urls_into_links(&$text) {
}
// TODO MDL-21296 - use of unicode modifiers may cause a timeout
+ $urlstart = '(?:http(s)?://|(?<!://)(www\.))';
$domainsegment = '(?:[\pLl0-9][\pLl0-9-]*[\pLl0-9]|[\pLl0-9])';
$numericip = '(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3})';
$port = '(?::\d*)';
@@ -131,7 +132,7 @@ protected function convert_urls_into_links(&$text) {
$querystring = '(?:\?(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)';
$fragment = '(?:\#(?:[\pL0-9\.!$&\'\(\)*+,;=_~:@/?-]|%[a-fA-F0-9]{2})*)';
- $regex = "(?<!=[\"'])(?:http(s)?://|(www\.))((?:$domainsegment\.)+$domainsegment|$numericip)" .
+ $regex = "(?<!=[\"'])$urlstart((?:$domainsegment\.)+$domainsegment|$numericip)" .
"($port?$path$querystring?$fragment?)(?<![]),.;])";
if ($unicoderegexp) {
$regex = '#' . $regex . '#ui';
View
4 filter/urltolink/tests/filter_test.php
@@ -137,11 +137,13 @@ function get_convert_urls_into_links_test_cases() {
'<br />This is some text. www.moodle.com then some more text<br />' => '<br />This is some text. <a href="http://www.moodle.com" class="_blanktarget">www.moodle.com</a> then some more text<br />',
//check we aren't modifying img tags
'image<img src="http://moodle.org/logo/logo-240x60.gif" />' => 'image<img src="http://moodle.org/logo/logo-240x60.gif" />',
- 'image<img src="www.moodle.org/logo/logo-240x60.gif" />' => 'image<img src="www.moodle.org/logo/logo-240x60.gif" />',
+ 'image<img src="www.moodle.org/logo/logo-240x60.gif" />' => 'image<img src="www.moodle.org/logo/logo-240x60.gif" />',
+ 'image<img src="http://www.example.com/logo.gif" />' => 'image<img src="http://www.example.com/logo.gif" />',
//and another url within one tag
'<td background="http://moodle.org">&nbsp;</td>' => '<td background="http://moodle.org">&nbsp;</td>',
'<td background="www.moodle.org">&nbsp;</td>' => '<td background="www.moodle.org">&nbsp;</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">&nbsp;</td>' => '<td background="https://www.moodle.org">&nbsp;</td>',
//partially escaped img tag
'partially escaped img tag &lt;img src="http://moodle.org/logo/logo-240x60.gif" />' => 'partially escaped img tag &lt;img src="http://moodle.org/logo/logo-240x60.gif" />',
//fully escaped img tag. Commented out as part of MDL-21183
Please sign in to comment.
Something went wrong with that request. Please try again.