Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/23/2015 01:42:40 PM (10 years ago)
Author:
boonebgorges
Message:

Improve the HTML-handling logic of bp_create_excerpt().

  • The regular expression that detects tags should be less generous, to avoid false matches.
  • Word boundary detection, as used when exact=false, should never return a space character inside of an HTML tag (such as the space in <a href="http://example.com">).

These changes fix some tag-parsing issues introduced in [9523].

Fixes #6517.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/template/bpCreateExcerpt.php

    r9819 r9962  
    6262        ) ) );
    6363    }
     64
     65    /**
     66     * @ticket BP6517
     67     */
     68    public function test_string_should_not_be_cut_mid_tag_when_exact_is_false() {
     69        $text = '<p><span>Foo</span> <a href="http://example.com">Bar</a> Baz.</p><p>Foo Bar Baz</p>';
     70        $actual = bp_create_excerpt( $text, 7, array(
     71            'html' => true,
     72            'ending' => '',
     73            'exact' => false,
     74        ) );
     75        $this->assertSame( '<p><span>Foo</span> <a href="http://example.com">Bar</a></p>', $actual );
     76    }
    6477}
Note: See TracChangeset for help on using the changeset viewer.