mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 20:58:30 +01:00
Corrected internal parser conflict when code/pre tags contained curly brackets.
This commit is contained in:
parent
0e3f87cf25
commit
1d4bc0e95a
@ -5372,12 +5372,12 @@ return;
|
||||
$html = str_replace('>','>',$html);
|
||||
}
|
||||
|
||||
$html = str_replace(' ', '{E_PARSER_CLEAN_HTML_NON_BREAKING_SPACE}', $html); // prevent replacement of with spaces.
|
||||
$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("\n", "{E_PARSER_CLEAN_HTML_LINE_BREAK}", $html);
|
||||
|
||||
|
||||
$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);
|
||||
|
||||
|
||||
if(strpos($html, "<body")===false) // HTML Fragment
|
||||
@ -5529,16 +5529,16 @@ return;
|
||||
$value = str_replace('<br></br>', PHP_EOL, $value);
|
||||
|
||||
}
|
||||
|
||||
if($node->nodeName === 'code')
|
||||
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('{', '{{{', $value); // temporarily change {e_XXX} to {{{e_XXX}}}
|
||||
$value = str_replace('}', '}}}', $value); // temporarily change {e_XXX} to {{{e_XXX}}}
|
||||
$value = str_replace('__E_PARSER_CLEAN_HTML_CURLY_OPEN__', '{{{', $value); // temporarily change {e_XXX} to {{{e_XXX}}}
|
||||
$value = str_replace('__E_PARSER_CLEAN_HTML_CURLY_CLOSED__', '}}}', $value); // temporarily change {e_XXX} to {{{e_XXX}}}
|
||||
|
||||
|
||||
$newNode = $doc->createElement($node->nodeName);
|
||||
$newNode->nodeValue = $value;
|
||||
@ -5591,13 +5591,16 @@ return;
|
||||
// Workaround for https://bugs.php.net/bug.php?id=76285
|
||||
// Part 2 of 2
|
||||
$cleaned = str_replace("\n", "", $cleaned);
|
||||
$cleaned = str_replace("{E_PARSER_CLEAN_HTML_LINE_BREAK}", "\n", $cleaned);
|
||||
$cleaned = str_replace("__E_PARSER_CLEAN_HTML_LINE_BREAK__", "\n", $cleaned);
|
||||
|
||||
$cleaned = str_replace('{E_PARSER_CLEAN_HTML_NON_BREAKING_SPACE}', ' ', $cleaned); // prevent replacement of with spaces. - convert back.
|
||||
$cleaned = str_replace('__E_PARSER_CLEAN_HTML_NON_BREAKING_SPACE__', ' ', $cleaned); // prevent replacement of with spaces. - convert back.
|
||||
|
||||
$cleaned = str_replace('{{{','{', $cleaned); // convert shortcode temporary triple-curly braces back to entities.
|
||||
$cleaned = str_replace('}}}','}', $cleaned); // convert shortcode temporary triple-curly braces back to entities.
|
||||
|
||||
$cleaned = str_replace("__E_PARSER_CLEAN_HTML_CURLY_OPEN__","{", $cleaned);
|
||||
$cleaned = str_replace("__E_PARSER_CLEAN_HTML_CURLY_CLOSED__","}", $cleaned);
|
||||
|
||||
$cleaned = str_replace(array('<body>','</body>'),'', $cleaned); // filter out tags.
|
||||
|
||||
return trim($cleaned);
|
||||
|
@ -350,6 +350,23 @@ TMP;
|
||||
'input' => '< 200',
|
||||
'expected' => '< 200',
|
||||
),
|
||||
23 => array(
|
||||
'input' => '[html]<pre>echo {e_BASE}."index.php";</pre>[/html]',
|
||||
'expected' => '[html]<pre>echo {e_BASE}."index.php";</pre>[/html]'
|
||||
),
|
||||
24 => array(
|
||||
'input' => '[html]<code>echo {e_BASE}."index.php";</code>[/html]',
|
||||
'expected' => '[html]<code>echo {e_BASE}."index.php";</code>[/html]'
|
||||
),
|
||||
25 => array(
|
||||
'input' => '[html]<img src="{e_BASE}image.jpg" alt="">[/html]',
|
||||
'expected' => '[html]<img src="{e_BASE}image.jpg" alt="">[/html]'
|
||||
),
|
||||
26 => array(
|
||||
'input' => "[html]<code>function sc_my_shortcode(){\nreturn \"Something\";}</code>[/html]",
|
||||
'expected' => "[html]<code>function sc_my_shortcode(){\nreturn "Something";}</code>[/html]"
|
||||
),
|
||||
|
||||
|
||||
);
|
||||
|
||||
@ -1013,6 +1030,9 @@ TMP;
|
||||
// 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="">'),
|
||||
|
||||
);
|
||||
|
||||
@ -1020,7 +1040,6 @@ TMP;
|
||||
{
|
||||
$result = $this->tp->cleanHtml($var['html']);
|
||||
$this->assertEquals($var['expected'], $result);
|
||||
// FIXME: This test doesn't do anything?
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user