Problem/Motivation
While reviewing
π
preg_split in _filter_url breaks for long html tags
Fixed
, @larowlan and I noticed some ways we could simplify _filter_url()
. We agreed that those changes are out of scope for that issue, so we plan to make the changes here.
Proposed resolution
The outer loop starts with escaping HTML comments and ends with restoring them:
foreach ($tasks as $task => $pattern) {
// HTML comments need to be handled separately, as they may contain HTML
// markup, especially a '>'. Therefore, remove all comment contents and add
// them back later.
_filter_url_escape_comments('', TRUE);
$text = $text ? preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text) : $text;
// ...
// Revert to the original comment contents
_filter_url_escape_comments('', FALSE);
$text = $text ? preg_replace_callback('`<!--(.*?)-->`', '_filter_url_escape_comments', $text) : $text;
}
None of the callbacks in the body of the loop introduce new HTML comments, so we can move the calls to _filter_url_escape_comments()
out of the loop.
Once we do that, we can replace the change from
π
preg_split in _filter_url breaks for long html tags
Fixed
with an exit-early strategy (if (...) { continue; }
).
Next, the inner loop has the structure
for ($i = 0; $i < count($chunks); $i++) {
if ($chunk_type == 'text') {
//...
}
else {
if ($open_tag == '') {
// ...
}
else {
// ...
}
}
That can be simplified: make it three if
blocks, with a continue
statement at the end of the first two.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
N/A