Make WordPress Core

Ticket #56434: 56434.diff

File 56434.diff, 2.4 KB (added by costdev, 3 years ago)
  • src/wp-includes/formatting.php

    diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
    index 8d41efffdc..b54352d1ae 100644
    a b function normalize_whitespace( $str ) { 
    53905390 * @return string The processed string.
    53915391 */
    53925392function wp_strip_all_tags( $string, $remove_breaks = false ) {
     5393        if ( ! is_string( $string ) ) {
     5394                _doing_it_wrong(
     5395                        __FUNCTION__,
     5396                        sprintf(
     5397                                /* translators: %s: The `$string` argument. */
     5398                                __( 'The %s argument must be a string' ),
     5399                                '$string'
     5400                        ),
     5401                        '6.1.0'
     5402                );
     5403
     5404                return '';
     5405        }
     5406
    53935407        $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
    53945408        $string = strip_tags( $string );
    53955409
  • tests/phpunit/tests/formatting/wpStripAllTags.php

    diff --git a/tests/phpunit/tests/formatting/wpStripAllTags.php b/tests/phpunit/tests/formatting/wpStripAllTags.php
    index 2ef332e62e..78518d1f63 100644
    a b class Tests_Formatting_wpStripAllTags extends WP_UnitTestCase { 
    3131                $text = "lorem<style>* { display: 'none' }<script>alert( document.cookie )</script></style>ipsum";
    3232                $this->assertSame( 'loremipsum', wp_strip_all_tags( $text ) );
    3333        }
     34
     35        /**
     36         * Tests that `wp_strip_all_tags()` throws a `_doing_it_wrong()` and returns
     37         * an empty string when passed a non-string `$string` argument.
     38         *
     39         * @ticket 56434
     40         *
     41         * @expectedIncorrectUsage wp_strip_all_tags
     42         *
     43         * @dataProvider data_wp_strip_all_tags_should_throw_doing_it_wrong_for_non_string
     44         *
     45         * @param mixed $non_string A non-string value.
     46         */
     47        public function test_wp_strip_all_tags_should_return_empty_string_and_throw_doing_it_wrong_for_non_string_arg( $non_string ) {
     48                $this->assertSame( '', wp_strip_all_tags( $non_string ) );
     49        }
     50
     51        /**
     52         * Data provider.
     53         *
     54         * @return array
     55         */
     56        public function data_wp_strip_all_tags_should_throw_doing_it_wrong_for_non_string() {
     57                return array(
     58                        '(int) 0'           => array( 'non_string' => 0 ),
     59                        '(int) 1'           => array( 'non_string' => 1 ),
     60                        '(bool) false'      => array( 'non_string' => false ),
     61                        '(bool) true'       => array( 'non_string' => true ),
     62                        'an empty array'    => array( 'non_string' => array() ),
     63                        'a non-empty array' => array( 'non_string' => array( 'a string' ) ),
     64                        'an object'         => array( 'non_string' => new stdClass() ),
     65                );
     66        }
    3467}
    3568