Make WordPress Core


Ignore:
Timestamp:
06/17/2024 12:02:50 PM (6 months ago)
Author:
dmsnell
Message:

KSES: Fix tests and detection of HTML Bogus Comment spans.

In [58418] a test was added without the test_ prefix in its function
name, and because of that, it wasn't run in the test suite.
The prefix has been added to ensure that it runs.

In the original patch, due to a logical bug, a recursive loop to
transform the inside contents of the bogus comments was never run
more than once. This has been fixed.

This patch also includes one more case where kses wasn't
properly detecting the bogus comment state, and adds a test case
to cover this. It limits itself to some but not all constructions
of invalid markup declaration so that it doesn't conflict with
existing behaviors around those and other kinds of invalid comments.

Props ellatrix, dmsnell.
See #61009.
Follow-up to [58418].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/kses.php

    r58418 r58424  
    19371937     * @ticket 61009
    19381938     *
     1939     * @dataProvider data_html_containing_various_kinds_of_html_comments
     1940     *
    19391941     * @param string $html_comment    HTML containing a comment; must not be a valid comment
    19401942     *                                but must be syntax which a browser interprets as a comment.
    19411943     * @param string $expected_output How `wp_kses()` ought to transform the comment.
    19421944     */
    1943     public function wp_kses_preserves_html_comments( $html_comment, $expected_output ) {
     1945    public function test_wp_kses_preserves_html_comments( $html_comment, $expected_output ) {
    19441946        $this->assertSame(
    19451947            $expected_output,
     
    19581960            'Normative HTML comment'            => array( 'before<!-- this is a comment -->after', 'before<!-- this is a comment -->after' ),
    19591961            'Closing tag with invalid tag name' => array( 'before<//not a tag>after', 'before<//not a tag>after' ),
     1962            'Incorrectly opened comment (Markup declaration)' => array( 'before<!also not a tag>after', 'before<!also not a tag>after' ),
    19601963        );
    19611964    }
Note: See TracChangeset for help on using the changeset viewer.