Make WordPress Core


Ignore:
Timestamp:
08/18/2020 03:08:19 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Formatting: Make the check for empty text in wp_trim_excerpt() more resilient.

This addresses a regression in [47808], which caused excerpts to be generated from post content if an empty string is passed, but not for other values considered empty, e.g. null or false.

Props riaanlom, laxman-prajapati, SergeyBiryukov.
Fixes #51042.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/WpTrimExcerpt.php

    r46586 r48817  
    6767        }
    6868    }
     69
     70    /**
     71     * @ticket 51042
     72     */
     73    public function test_should_generate_excerpt_for_empty_values() {
     74        $post = self::factory()->post->create(
     75            array(
     76                'post_content' => 'Post content',
     77            )
     78        );
     79
     80        $this->assertSame( 'Post content', wp_trim_excerpt( '', $post ) );
     81        $this->assertSame( 'Post content', wp_trim_excerpt( null, $post ) );
     82        $this->assertSame( 'Post content', wp_trim_excerpt( false, $post ) );
     83    }
    6984}
Note: See TracChangeset for help on using the changeset viewer.