User tests: Successful: Unsuccessful:
Better/faster regular expression for plugin "Content - Email Cloaking". No other changes.
Take a look at #11353 for more information.
Check if the email address between the tags is properly masked/cloaked.
E.g. <span title="xxx@example.com"><strong>xxx@example.com</strong></span>
Only email between tags should be masked as before PR.
Execute a few php commands:
$a = array('<p><img src="data:image/png;base64,', '" alt="image" /></p>');
$b = implode(bin2hex(openssl_random_pseudo_bytes(50000)), $a);
$searchEmail = '([\w\.\'\-\+]+\@(?:[a-z0-9\.\-]+\.)+(?:[a-zA-Z0-9\-]{2,10}))';
$pattern_old = '~(?![^<>]*>)' . $searchEmail . '~i';
$pattern_new = '~<[^<]*>(*SKIP)(*F)|' . $searchEmail . '~i';
$t=microtime(1);preg_match($pattern_old, $b, $regs, PREG_OFFSET_CAPTURE);printf("%.5F", microtime(1)-$t);
$t=microtime(1);preg_match($pattern_new, $b, $regs, PREG_OFFSET_CAPTURE);printf("%.5F", microtime(1)-$t);
No changes, only time improvement.
preg_match
on line 491 runs slowly.
joomla-cms/plugins/content/emailcloak/emailcloak.php
Lines 484 to 491 in 899e7c9
No
Status | New | ⇒ | Pending |
Category | ⇒ | Front End Plugins |
Labels |
Added:
?
|
hi nice performance improvement!
in theory similiar improvement could be used in several places with negative lookahead to improve performance.
example the ampReplace method (used in many uri generation - https://github.com/joomla/joomla-cms/search?q=ampReplace) method (https://github.com/joomla-framework/filter/blob/master/src/OutputFilter.php#L160)
in that case maybe (didn't test) this regex would work '/&[&#](*SKIP)(*F)|&[\w]+;(*SKIP)(*F)|&/'
the sef plugin (https://github.com/joomla/joomla-cms/blob/staging/plugins/system/sef/sef.php#L126) also has several negative lookahead regex
and surely many other places in the joomla core
i've Tested successfully this PR but unable to report the test result on github even it's ok on the issue tracker
https://issues.joomla.org/tracker/joomla-cms/20956#event-374308
testers are like "pandas" ... in extinction
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-07-21 01:03:27 |
Closed_By | ⇒ | mbabker | |
Labels |
Added:
?
|
I have tested this item✅ successfully on 324f140
Thanks !!!
wanted to take time to look into this but neglected it
Current performance of this regular expression is just terrible, O(N*N) for N length of HTML body
Running in pages with a lot of HTML is terribly slow, and can even result in timeouts
After PR it is O(N)
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20956.