Basic unit tests and additional documentation for wp_strip_all_tags().
props joehoyle. fixes #25507. git-svn-id: https://develop.svn.wordpress.org/trunk@27042 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c759a54b2c
commit
0406e11513
@ -3568,6 +3568,10 @@ function normalize_whitespace( $str ) {
|
||||
|
||||
/**
|
||||
* Properly strip all HTML tags including script and style
|
||||
*
|
||||
* This differs from strip_tags() because it removes the contents of
|
||||
* the <script> and <style> tags. E.g. strip_tags( '<script>something</script>' )
|
||||
* will return 'something'. wp_strip_all_tags will return ''
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
|
33
tests/phpunit/tests/formatting/WPStripAllTags.php
Normal file
33
tests/phpunit/tests/formatting/WPStripAllTags.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Test wp_strip_all_tags()
|
||||
*
|
||||
* @group formatting
|
||||
*/
|
||||
class Tests_Formatting_WPStripAllTags extends WP_UnitTestCase {
|
||||
|
||||
function test_wp_strip_all_tags() {
|
||||
|
||||
$text = 'lorem<br />ipsum';
|
||||
$this->assertEquals( 'loremipsum', wp_strip_all_tags( $text ) );
|
||||
|
||||
$text = "lorem<br />\nipsum";
|
||||
$this->assertEquals( "lorem\nipsum", wp_strip_all_tags( $text ) );
|
||||
|
||||
// test removing breaks is working
|
||||
$text = "lorem<br />ipsum";
|
||||
$this->assertEquals( "loremipsum", wp_strip_all_tags( $text, true ) );
|
||||
|
||||
// test script / style tag's contents is removed
|
||||
$text = "lorem<script>alert(document.cookie)</script>ipsum";
|
||||
$this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) );
|
||||
|
||||
$text = "lorem<style>* { display: 'none' }</style>ipsum";
|
||||
$this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) );
|
||||
|
||||
// test "marlformed" markup of contents
|
||||
$text = "lorem<style>* { display: 'none' }<script>alert( document.cookie )</script></style>ipsum";
|
||||
$this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user