Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-38698 filter_urltolink: Do not link the URL property of CSS

  • Loading branch information...
commit 3d947610a0fde79aef850df0abb5d7ad111fd768 1 parent c9a3d37
Frédéric Massart FMCorz authored
9 filter/urltolink/filter.php
View
@@ -132,8 +132,13 @@ protected function convert_urls_into_links(&$text) {
$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 {
5 filter/urltolink/tests/filter_test.php
View
@@ -144,6 +144,11 @@ function get_convert_urls_into_links_test_cases() {
'<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>',
+ // 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 &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.