mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 14:46:56 +02:00
Issue #4058 Pre/Code tag TinyMce line-break issue and tests.
This commit is contained in:
@@ -5376,6 +5376,7 @@ return;
|
||||
$html = str_replace(' ', '__E_PARSER_CLEAN_HTML_NON_BREAKING_SPACE__', $html); // prevent replacement of with spaces.
|
||||
// Workaround for https://bugs.php.net/bug.php?id=76285
|
||||
// Part 1 of 2
|
||||
$html = str_replace("\r", "", $html); // clean out windows line-breaks.
|
||||
$html = str_replace("\n", "__E_PARSER_CLEAN_HTML_LINE_BREAK__", $html);
|
||||
$html = str_replace("{", "__E_PARSER_CLEAN_HTML_CURLY_OPEN__", $html);
|
||||
$html = str_replace("}", "__E_PARSER_CLEAN_HTML_CURLY_CLOSED__", $html);
|
||||
@@ -5527,14 +5528,13 @@ return;
|
||||
{
|
||||
$value = preg_replace('/^<pre[^>]*>/', '', $value);
|
||||
$value = str_replace("</pre>", "", $value);
|
||||
$value = str_replace('<br></br>', PHP_EOL, $value);
|
||||
|
||||
$value = str_replace('<br></br>', "__E_PARSER_CLEAN_HTML_LINE_BREAK__", $value);
|
||||
}
|
||||
elseif($node->nodeName === 'code')
|
||||
{
|
||||
$value = preg_replace('/^<code[^>]*>/', '', $value);
|
||||
$value = str_replace("</code>", "", $value);
|
||||
$value = str_replace("<br></br>", PHP_EOL, $value);
|
||||
$value = str_replace("<br></br>", "__E_PARSER_CLEAN_HTML_LINE_BREAK__", $value);
|
||||
}
|
||||
|
||||
$value = str_replace('__E_PARSER_CLEAN_HTML_CURLY_OPEN__', '{{{', $value); // temporarily change {e_XXX} to {{{e_XXX}}}
|
||||
|
@@ -64,6 +64,20 @@ TMP;
|
||||
$expected = "<div class='bbcode-center' style='text-align:center'><img src='".e_HTTP."e107_images/generic/blank_avatar.jpg' width='' alt='Blank Avatar' title='Blank Avatar' class='img-rounded rounded bbcode bbcode-img' /></div>";
|
||||
|
||||
$this->assertEquals($expected, $actual, "BBcode parsing failed on [img]");
|
||||
/*
|
||||
$src = "[html]
|
||||
<pre>$sql = e107::getDb();
|
||||
$sql->select('tablename', 'field1, field2', 'field_id = 1');
|
||||
while($row = $sql->fetch())
|
||||
{
|
||||
echo $row['field1'];
|
||||
}</pre>
|
||||
[/html]";
|
||||
|
||||
$actual = $this->tp->toHTML($src,true);
|
||||
$expected = '';
|
||||
|
||||
$this->assertEquals($expected, $actual, "BBcode parsing failed on <pre>");*/
|
||||
|
||||
|
||||
}
|
||||
@@ -366,7 +380,11 @@ TMP;
|
||||
'input' => "[html]<code>function sc_my_shortcode(){\nreturn \"Something\";}</code>[/html]",
|
||||
'expected' => "[html]<code>function sc_my_shortcode(){\nreturn "Something";}</code>[/html]"
|
||||
),
|
||||
|
||||
27 => array(
|
||||
'input' =>"[html]<pre class=\"whatever\">require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF);</pre>",
|
||||
'expected' =>"[html]<pre class="whatever">require_once("class2.php");\nrequire_once(HEADERF);\necho "test";<br>\nrequire_once(FOOTERF);</pre>",
|
||||
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
@@ -1030,16 +1048,44 @@ TMP;
|
||||
public function testCleanHtml()
|
||||
{
|
||||
$tests = array(
|
||||
0 => array('html' => "<svg/onload=prompt(1)//", 'expected' => '<svg/onload=prompt(1)//'),
|
||||
0 => array(
|
||||
'html' => "<svg/onload=prompt(1)//",
|
||||
'expected' => '<svg/onload=prompt(1)//'
|
||||
),
|
||||
// 1 => array('html' => '<script>alert(123)</script>', 'expected'=>''),
|
||||
// 2 => array('html' => '"><script>alert(123)</script>', 'expected'=>'">'),
|
||||
3 => array('html' => '< 200', 'expected'=>'< 200'),
|
||||
4 => array('html' => "<code>function sc_my_shortcode(){\nreturn \"Something\";}</code>", 'expected' => "<code>function sc_my_shortcode(){\nreturn \"Something\";}</code>"),
|
||||
5 => array('html' => "<pre class=\"prettyprint linenums\">function sc_my_shortcode(){\nreturn \"Something\";}</pre>", 'expected' => "<pre class=\"prettyprint linenums\">function sc_my_shortcode(){\nreturn \"Something\";}</pre>"),
|
||||
6 => array('html' => '<img src="{e_BASE}image.jpg" alt="">', 'expected'=>'<img src="{e_BASE}image.jpg" alt="">'),
|
||||
3 => array(
|
||||
'html' => '< 200',
|
||||
'expected'=>'< 200'
|
||||
),
|
||||
4 => array(
|
||||
'html' => "<code>function sc_my_shortcode(){\nreturn \"Something\";}</code>",
|
||||
'expected' => "<code>function sc_my_shortcode(){\nreturn \"Something\";}</code>"
|
||||
),
|
||||
5 => array(
|
||||
'html' => "<pre class=\"prettyprint linenums\">function sc_my_shortcode(){\nreturn \"Something\";}</pre>",
|
||||
'expected' => "<pre class=\"prettyprint linenums\">function sc_my_shortcode(){\nreturn \"Something\";}</pre>"
|
||||
),
|
||||
6 => array(
|
||||
'html' => '<img src="{e_BASE}image.jpg" alt="">',
|
||||
'expected' =>'<img src="{e_BASE}image.jpg" alt="">'
|
||||
),
|
||||
7 => array( // with <br> inside <pre> ie. TinyMce
|
||||
'html' => '<pre class="whatever">require_once("class2.php");<br>require_once(HEADERF);<br>echo "test";<br><br>require_once(FOOTERF);</pre>',
|
||||
'expected' => "<pre class=\"whatever\">require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF);</pre>"
|
||||
),
|
||||
8 => array( // with \n
|
||||
'html' => "<pre class=\"whatever\">require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF);</pre>",
|
||||
'expected' => "<pre class=\"whatever\">require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF);</pre>"
|
||||
),
|
||||
9 => array( // with \r\n (windows) line-breaks.
|
||||
'html' => "<pre class=\"whatever\">require_once(\"class2.php\");\r\nrequire_once(HEADERF);\r\necho \"test\";<br>\r\nrequire_once(FOOTERF);</pre>",
|
||||
'expected' => "<pre class=\"whatever\">require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF);</pre>"
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
|
||||
foreach($tests as $var)
|
||||
{
|
||||
$result = $this->tp->cleanHtml($var['html']);
|
||||
|
Reference in New Issue
Block a user