?
avatar nextend
nextend
26 Jun 2015

Bug

The problem is that I'm using images in the style attributes for background images and I'm set the image urls with a full url:

<div style="background-image: url(&#039;http://test.org/test.png&#039;)"></div>

Note that the ' in the url() are properly encoded for HTML attributes. This is when the issue comes, the following regexp only match the not encoded ' and " characters and not the encoded ones. The regexp should be fixed by adding
' => '
" => "

The regexp is in plugins/system/sef/sef.php which used to find image urls in style attributes to fix them to the current site's relative path:

$regex = '#style\s=\s\'\":\surl\s([\'\"]?(?!/|' . $protocols . '|#)([^)\'\"]+)[\'\"]?)#m';

Test:

<div style="background-image: url(&#039;http://test.org/test.png&#039;)"></div>

Result:

<div style="background-image: url("/my/site/path/&#039;http://test.org/test.png&#039;")"></div>

Desired result: - (Regexp do not match this url.)

<div style="background-image: url(&#039;http://test.org/test.png&#039;)"></div>

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar nextend nextend - open - 26 Jun 2015
avatar zero-24 zero-24 - change - 26 Jun 2015
Labels Added: ?
avatar zero-24 zero-24 - change - 26 Jun 2015
Category Router / SEF
avatar ggppdk
ggppdk - comment - 28 Jun 2015

The regular expression has some negative look ahead to avoid matching things like:
url( '/
url( 'http://

we could add & # 039; to the negative lookahead:

Replacing:

// Background image.
$regex  = '#style\s*=\s*[\'\"](.*):\s*url\s*\([\'\"]?(?!/|' . $protocols . '|\#)([^\)\'\"]+)[\'\"]?\)#m';

with:

// Background image.
$regex  = '#style\s*=\s*[\'\"](.*):\s*url\s*\([\'\"]?(?!/|\&\#039;|' . $protocols . '|\#)([^\)\'\"]+)[\'\"]?\)#m';
avatar nextend
nextend - comment - 15 Dec 2015

For us the solution was to use uppercase URL in our HTML, as the SEF preg_match do not ignore case :)

Also I have one other use case when the regexp fails. Nowadays protocol relative urls are popular, so this would be perfect if you have a site with http and https too:

But the regular expression is not able to match the protocol so it fails and adds the previously mentioned path to the url.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7267.

avatar brianteeman brianteeman - change - 3 Aug 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-08-03 12:49:55
Closed_By brianteeman
avatar brianteeman
brianteeman - comment - 3 Aug 2016

Closed as we have a PR for testing #11412


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7267.

Add a Comment

Login with GitHub to post a comment