? Success

User tests: Successful: Unsuccessful:

avatar nextend
nextend
15 Jan 2019

Pull Request for Issue #23548

In the original version, the regexp matches everything until it finds a : character. So instead using a plain wildcard, it would be better to match every character until a HTML tag close character found [^>].

Original
$regex = '#style=\s*([\'\"])(.*):' . $regex_url . '#m';

Updated
$regex = '#style=\s*([\'\"])([^>]*):' . $regex_url . '#m';

Test code

<?php
$protocols = '[a-zA-Z0-9\-]+:';

$regex_url = '\s*url\s*\(([\'\"]|\&\#0?3[49];)?(?!/|\&\#0?3[49];|' . $protocols . '|\#)([^\)\'\"]+)([\'\"]|\&\#0?3[49];)?\)';
$regex     = '#style=\s*([\'\"])([^>]*):' . $regex_url . '#m';

$base = 'https://mybase.com/';

$buffer = '';

for ($i = 0; $i < 4000; $i++) {
    $buffer .= '<div style="background-image: url(\'/picture.jpg\');">' . $i . '</div>';
}

echo preg_replace($regex, 'style=$1$2: url($3' . $base . '$4$5)', $buffer);
avatar nextend nextend - open - 15 Jan 2019
avatar nextend nextend - change - 15 Jan 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 15 Jan 2019
Category Front End Plugins
avatar nextend nextend - change - 15 Jan 2019
The description was changed
avatar nextend nextend - edited - 15 Jan 2019
avatar nextend nextend - change - 15 Jan 2019
The description was changed
avatar nextend nextend - edited - 15 Jan 2019
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 24 Apr 2019

@nextend please give Instructions how this Pull Request can be tested.

avatar nextend
nextend - comment - 24 Apr 2019

@franz-wohlkoenig, Well, if there is a test case which tests the original code, that test should work fine.

If there is no test case yet, then the test case would contain different style attributes which contains url() like:

<div style="background: #234323;"></div> -> No match
<div style="background-image: url('/picture.jpg');"></div> -> Match
<div style="background-image: url(\"/picture.jpg\");"></div> -> Match
<div style="background-image: url(\"/picture.jpg\");"></div> -> Match
<div style="background-image: url(\"http://abc.com/picture.jpg\");"></div> -> Match

My suggestion changes (.*) to ([^>]*). Instead of matching everything, it matches until the first occurrence of the > character. So my suggestion can fail, if there is a > in the style attribute. We should find out if style attribute can contain raw > character.

What I can think of:

  • url() is not allowed to contain raw > characters as it is unsafe. encodeUri() translates it to %3E
avatar nextend nextend - change - 24 Apr 2019
Labels Removed: J3 Issue
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 24 Apr 2019

Thanks @nextend, hopefully 2 testers understand and test :-)

avatar laoneo
laoneo - comment - 4 Apr 2022

Sorry that it took so long to respond. As performance improvements are a welcome addition in Joomla, I would like to ask you to rebase this pr to the 4.2 branch. Please also add clear instructions how this pr can be tested as it contains a change in an important part of Joomla, which will likely affect many users when something doesn't work as before. In the meantime I'm closing the pr, when ready, please reopen again. Thanks for your help making Joomla better.

avatar laoneo laoneo - change - 4 Apr 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-04-04 11:09:49
Closed_By laoneo
Labels Added: ?
Removed: ?
avatar laoneo laoneo - close - 4 Apr 2022
avatar 3radfahrer
3radfahrer - comment - 11 May 2022

Well that bug still exists, at least in the current 3.x branch and affects performance heavily or stops the site from working at all. The problem is well described, a solution is presented as well. Please take care of this bug instead of just closing the pr without further looking into it. I would like to contribute, but I am not familiar with writing test cases.

Add a Comment

Login with GitHub to post a comment