mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-12 06:20:06 +00:00
HTML API: Add support for a few invalid HTML comment forms.
- Comments created by means of a tag closer with an invalid tag name, e.g. `</3>`. - Comments closed with the invalid `--!>` closer. (Comments should be closed by `-->` but if the `!` appears it will also close it, in error.) - Empty tag name elements, which are technically skipped over and aren't comments, e.g. `</>`. Props dmsnell, costdev. Fixes #58007. git-svn-id: https://develop.svn.wordpress.org/trunk@55667 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1732,6 +1732,47 @@ HTML;
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid tag names are comments on tag closers.
|
||||
*
|
||||
* @ticket 58007
|
||||
*
|
||||
* @link https://html.spec.whatwg.org/#parse-error-invalid-first-character-of-tag-name
|
||||
*
|
||||
* @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments
|
||||
*
|
||||
* @param string $html_with_markers HTML containing an invalid tag closer whose element before and
|
||||
* element after contain the "start" and "end" CSS classes.
|
||||
*/
|
||||
public function test_next_tag_ignores_invalid_first_character_of_tag_name_comments( $html_with_markers ) {
|
||||
$p = new WP_HTML_Tag_Processor( $html_with_markers );
|
||||
$p->next_tag( array( 'class_name' => 'start' ) );
|
||||
$p->next_tag();
|
||||
|
||||
$this->assertSame( 'end', $p->get_attribute( 'class' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data_next_tag_ignores_invalid_first_character_of_tag_name_comments() {
|
||||
return array(
|
||||
'Invalid tag openers as normal text' => array(
|
||||
'<ul><li><div class=start>I <3 when outflow > inflow</div><img class=end></li></ul>',
|
||||
),
|
||||
|
||||
'Invalid tag closers as comments' => array(
|
||||
'<ul><li><div class=start>I </3 when <img> outflow <br class=end> inflow</div></li></ul>',
|
||||
),
|
||||
|
||||
'Unexpected question mark instead of tag name' => array(
|
||||
'<div class=start><?xml-stylesheet type="text/css" href="style.css"?><hr class=end>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56299
|
||||
*
|
||||
@@ -1784,6 +1825,99 @@ HTML;
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the invalid comment closing syntax "--!>" properly closes a comment.
|
||||
*
|
||||
* @ticket 58007
|
||||
*
|
||||
* @covers WP_HTML_Tag_Processor::next_tag
|
||||
*
|
||||
*/
|
||||
public function test_allows_incorrectly_closed_comments() {
|
||||
$p = new WP_HTML_Tag_Processor( '<img id=before><!-- <img id=inside> --!><img id=after>--><img id=final>' );
|
||||
|
||||
$p->next_tag();
|
||||
$this->assertSame( 'before', $p->get_attribute( 'id' ), 'Did not find starting tag.' );
|
||||
|
||||
$p->next_tag();
|
||||
$this->assertSame( 'after', $p->get_attribute( 'id' ), 'Did not properly close improperly-closed comment.' );
|
||||
|
||||
$p->next_tag();
|
||||
$this->assertSame( 'final', $p->get_attribute( 'id' ), 'Did not skip over unopened comment-closer.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that unclosed and invalid comments don't trigger warnings or errors.
|
||||
*
|
||||
* @ticket 58007
|
||||
*
|
||||
* @covers WP_HTML_Tag_Processor::next_tag
|
||||
*
|
||||
* @dataProvider data_html_with_unclosed_comments
|
||||
*
|
||||
* @param string $html_ending_before_comment_close HTML with opened comments that aren't closed
|
||||
*/
|
||||
public function test_documents_may_end_with_unclosed_comment( $html_ending_before_comment_close ) {
|
||||
$p = new WP_HTML_Tag_Processor( $html_ending_before_comment_close );
|
||||
|
||||
$this->assertFalse( $p->next_tag() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data_html_with_unclosed_comments() {
|
||||
return array(
|
||||
'Shortest open valid comment' => array( '<!--' ),
|
||||
'Basic truncated comment' => array( '<!-- this ends --' ),
|
||||
'Comment with closer look-alike' => array( '<!-- this ends --x' ),
|
||||
'Comment with closer look-alike 2' => array( '<!-- this ends --!x' ),
|
||||
'Invalid tag-closer comment' => array( '</(when will this madness end?)' ),
|
||||
'Invalid tag-closer comment 2' => array( '</(when will this madness end?)--' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that abruptly-closed empty comments are properly closed.
|
||||
*
|
||||
* @ticket 58007
|
||||
*
|
||||
* @covers WP_HTML_Tag_Processor::next_tag
|
||||
*
|
||||
* @dataProvider data_abruptly_closed_empty_comments
|
||||
*
|
||||
* @param string $html_with_after_marker HTML to test with "id=after" on element immediately following an abruptly closed comment.
|
||||
*/
|
||||
public function test_closes_abrupt_closing_of_empty_comment( $html_with_after_marker ) {
|
||||
$p = new WP_HTML_Tag_Processor( $html_with_after_marker );
|
||||
$p->next_tag();
|
||||
$p->next_tag();
|
||||
|
||||
$this->assertSame( 'after', $p->get_attribute( 'id' ), 'Did not find tag after closing abruptly-closed comment' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data_abruptly_closed_empty_comments() {
|
||||
return array(
|
||||
'Empty comment with two dashes only' => array( '<hr><!--><hr id=after>' ),
|
||||
'Empty comment with two dashes only, improperly closed' => array( '<hr><!--!><hr id=inside>--><hr id=after>' ),
|
||||
'Comment with two dashes only, improperly closed twice' => array( '<hr><!--!><hr id=inside>--!><hr id=after>' ),
|
||||
'Empty comment with three dashes' => array( '<hr><!---><hr id=after>' ),
|
||||
'Empty comment with three dashes, improperly closed' => array( '<hr><!---!><hr id=inside>--><hr id=after>' ),
|
||||
'Comment with three dashes, improperly closed twice' => array( '<hr><!---!><hr id=inside>--!><hr id=after>' ),
|
||||
'Empty comment with four dashes' => array( '<hr><!----><hr id=after>' ),
|
||||
'Empty comment with four dashes, improperly closed' => array( '<hr><!----!><hr id=after>--><hr id=final>' ),
|
||||
'Comment with four dashes, improperly closed twice' => array( '<hr><!----!><hr id=after>--!><hr id=final>' ),
|
||||
'Comment with almost-closer inside' => array( '<hr><!-- ---!><hr id=after>--!><hr id=final>' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56299
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user