mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Making Sanitize::stripScripts() to remove multi-line script and style blocks. Fixes #657
This commit is contained in:
parent
95dbae8acf
commit
ce10c85367
2 changed files with 27 additions and 1 deletions
|
@ -156,7 +156,7 @@ class Sanitize {
|
|||
* @static
|
||||
*/
|
||||
function stripScripts($str) {
|
||||
return preg_replace('/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!--.*?-->/i', '', $str);
|
||||
return preg_replace('/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!--.*?-->/is', '', $str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -346,6 +346,32 @@ class SanitizeTest extends CakeTestCase {
|
|||
$expected = '';
|
||||
$result = Sanitize::stripScripts($string);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$string = <<<HTML
|
||||
text
|
||||
<style type="text/css">
|
||||
<!--
|
||||
#content { display:none; }
|
||||
-->
|
||||
</style>
|
||||
text
|
||||
HTML;
|
||||
$expected = "text\n\ntext";
|
||||
$result = Sanitize::stripScripts($string);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$string = <<<HTML
|
||||
text
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
alert('wooo');
|
||||
-->
|
||||
</script>
|
||||
text
|
||||
HTML;
|
||||
$expected = "text\n\ntext";
|
||||
$result = Sanitize::stripScripts($string);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue