Skip to:
Content

BuddyPress.org

Changeset 9707


Ignore:
Timestamp:
04/06/2015 09:14:50 PM (12 years ago)
Author:
boonebgorges
Message:

Don't let bp_create_excerpt() truncate to empty strings.

When the first word of a string is longer than the $length param, the word
should be truncated mid-word, even if exact=false.

Fixes #6254.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-template.php

    r9702 r9707  
    745745        if ( empty( $r['exact'] ) ) {
    746746                $spacepos = mb_strrpos( $truncate, ' ' );
    747                 if ( isset( $spacepos ) ) {
     747                if ( false !== $spacepos ) {
    748748                        if ( $r['html'] ) {
    749749                                $bits = mb_substr( $truncate, $spacepos );
  • trunk/tests/phpunit/testcases/core/template/bpCreateExcerpt.php

    r9523 r9707  
    4141                ) ) );
    4242        }
     43
     44        public function test_should_break_on_prior_word_boundary_when_exact_is_false() {
     45                $text = 'aaaaa aaaaaa';
     46                $expected = 'aaaaa';
     47                $this->assertSame( $expected, bp_create_excerpt( $text, 7, array(
     48                        'exact' => false,
     49                        'ending' => '',
     50                ) ) );
     51        }
     52
     53        /**
     54         * @ticket BP6254
     55         */
     56        public function test_should_trim_too_long_first_word_to_max_characters_even_when_exact_is_false() {
     57                $text = 'aaaaaaaaaaa';
     58                $expected = 'aaa';
     59                $this->assertSame( $expected, bp_create_excerpt( $text, 3, array(
     60                        'exact' => false,
     61                        'ending' => '',
     62                ) ) );
     63        }
    4364}
Note: See TracChangeset for help on using the changeset viewer.