Make WordPress Core

Ticket #25507: 25507.diff

File 25507.diff, 1.8 KB (added by joehoyle, 12 years ago)
  • src/wp-includes/formatting.php

     
    32493249
    32503250/**
    32513251 * Properly strip all HTML tags including script and style
     3252 *
     3253 * This differs from strip_tags() because it removes the contents of
     3254 * the <script> and <style> tags. E.g. strip_tags( '<script>something</script>' )
     3255 * will return 'something'. wp_strip_all_tags will return ''
    32523256 *
    32533257 * @since 2.9.0
    32543258 *
  • tests/phpunit/tests/functions.php

     
    519519                $this->assertCount( 7, $urls );
    520520                $this->assertEquals( array_slice( $original_urls, 0, 7 ), $urls );
    521521        }
     522
     523        /**
     524         * Test the wp_strip_all_tags function
     525         */
     526        function test_wp_strip_all_tags() {
     527
     528                $text = 'lorem<br />ipsum';
     529                $this->assertEquals( 'loremipsum', wp_strip_all_tags( $text ) );
     530
     531                $text = "lorem<br />\nipsum";
     532                $this->assertEquals( "lorem\nipsum", wp_strip_all_tags( $text ) );
     533
     534                // test removing breaks is working
     535                $text = "lorem<br />ipsum";
     536                $this->assertEquals( "loremipsum", wp_strip_all_tags( $text, true ) );
     537
     538                // test script / style tag's contents is removed
     539                $text = "lorem<script>alert(document.cookie)</script>ipsum";
     540                $this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) );
     541
     542                $text = "lorem<style>* { display: 'none' }</style>ipsum";
     543                $this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) );
     544
     545                // test "marlformed" markup of contents
     546                $text = "lorem<style>* { display: 'none' }<script>alert( document.cookie )</script></style>ipsum";
     547                $this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) );
     548        }
    522549}