Issue Bug Closed

#17899Misconfigured search/replace-patterns in t3lib_parsehtml->mapTags

Thomas Oppelt 12/07/07, 23:25 updated 09/09/13, 08:43

Description

I think there are misconfigured search-/replace-patterns used within t3lib_parsehtml->mapTags l.970:

$value = preg_replace(‘/’.preg_quote($ltChar).’(\/)?’.$from.’\s([^\>])*(\/)?\>/’, $ltChar2.’$1’.$to.’ $2$3>’, $value);

Example:

$from = ‘span’;
$to = ‘b’;
$ltChar = ‘<’; //default
$ltChar2 = ‘<’; //default
$value = ‘something‘;

Result of $value: ‘something‘

Does not make sense to me, searchpattern should be like:
’/’.preg_quote($ltChar).’(\/)?’.$from.’(\s[^\>]*)?(\/)?\>/‘
replacement without whitespace before $2:
$ltChar2.’$1’.$to.’$2$3>‘
results then in: ‘something‘
as expected.

Finally it does not make sense to preserve the attributes, so offer to overtake them or not by a preserving flag, summary:

function mapTags($value,$tags=array(),$ltChar=’<’,$ltChar2=’<’,$preserveAttribs=false) {

foreach($tags as $from => $to)    {
$value = preg_replace(‘/’.preg_quote($ltChar).’(\/)?’.$from.’(\s[^\>]*)?(\/)?\>/’, $ltChar2.’$1’.$to.($preserveAttribs?’$2$3>’:’$3>’), $value);
}
return $value;
}

Patch attached (created against 4.1.3 core, but it’s identical to 4.2alpha2)

(issue imported from #M6914)

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.