ENHANCEMENT: html2raw now properly replace strong tag with asterix #5494 (from r107443)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112600 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 03:51:55 +00:00
parent e07d56096d
commit bd927c9355
2 changed files with 16 additions and 6 deletions

View File

@ -264,14 +264,11 @@ class Convert {
$data = preg_replace("/<style(^A-Za-z0-9>][^>]*)?>.*?<\/style[^>]*>/i","", $data); $data = preg_replace("/<style(^A-Za-z0-9>][^>]*)?>.*?<\/style[^>]*>/i","", $data);
$data = preg_replace("/<script(^A-Za-z0-9>][^>]*)?>.*?<\/script[^>]*>/i","", $data); $data = preg_replace("/<script(^A-Za-z0-9>][^>]*)?>.*?<\/script[^>]*>/i","", $data);
// TODO Deal with attributes inside tags
if($config['ReplaceBoldAsterisk']) { if($config['ReplaceBoldAsterisk']) {
$data = str_ireplace( $data = preg_replace('%<(strong|b)( [^>]*)?>|</(strong|b)>%i','*',$data);
array('<strong>','</strong>','<b>','</b>'),
'*',
$data
);
} }
// Expand hyperlinks // Expand hyperlinks
if(!$preserveLinks && !$config['PreserveLinks']) { if(!$preserveLinks && !$config['PreserveLinks']) {
$data = preg_replace('/<a[^>]*href\s*=\s*"([^"]*)">(.*?)<\/a>/ie', "Convert::html2raw('\\2').'[\\1]'", $data); $data = preg_replace('/<a[^>]*href\s*=\s*"([^"]*)">(.*?)<\/a>/ie', "Convert::html2raw('\\2').'[\\1]'", $data);

View File

@ -28,6 +28,19 @@ class ConvertTest extends SapphireTest {
$this->assertEquals('Thisissomenormaltext', Convert::raw2htmlatt($val2), 'Normal text is not escaped'); $this->assertEquals('Thisissomenormaltext', Convert::raw2htmlatt($val2), 'Normal text is not escaped');
} }
function testHtml2raw() {
$val1 = 'This has a <strong>strong tag</strong>.';
$this->assertEquals('This has a *strong tag*.', Convert::xml2raw($val1), 'Strong tags are replaced with asterisks');
$val1 = 'This has a <b class="test" style="font-weight: bold">b tag with attributes</b>.';
$this->assertEquals('This has a *b tag with attributes*.', Convert::xml2raw($val1), 'B tags with attributes are replaced with asterisks');
$val2 = 'This has a <strong class="test" style="font-weight: bold">strong tag with attributes</STRONG>.';
$this->assertEquals('This has a *strong tag with attributes*.', Convert::xml2raw($val2), 'Strong tags with attributes are replaced with asterisks');
}
/** /**
* Tests {@link Convert::raw2xml()} * Tests {@link Convert::raw2xml()}
*/ */