Project

General

Profile

Actions

Bug #17899

closed

Misconfigured search/replace-patterns in t3lib_parsehtml->mapTags

Added by Thomas Oppelt almost 17 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2007-12-07
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.1
PHP Version:
5.2
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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 = '<span style="color:red">something</span>';

Result of $value: '<b ">something</span>'

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: '<b style="color:red">something</b>'
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)


Files

patch.diff (531 Bytes) patch.diff Administrator Admin, 2007-12-07 23:25
patch_02.diff (787 Bytes) patch_02.diff Administrator Admin, 2007-12-08 12:08
Actions

Also available in: Atom PDF