Skip to content

Commit c28ea1d

Browse files
committed
Add "area", "br", "embed", "img", "keygen", "wbr" tag rules
1 parent e707e37 commit c28ea1d

3 files changed

Lines changed: 46 additions & 9 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,29 @@ private function step_in_body() {
934934
$this->run_adoption_agency_algorithm();
935935
return true;
936936

937+
938+
/*
939+
* > An end tag whose tag name is "br"
940+
* > Parse error. Drop the attributes from the token, and act as described in the next
941+
* > entry; i.e. act as if this was a "br" start tag token with no attributes, rather
942+
* > than the end tag token that it actually is.
943+
*/
944+
case '-BR':
945+
$this->last_error = self::ERROR_UNSUPPORTED;
946+
throw new WP_HTML_Unsupported_Exception( "Closing BR tags require unimplemented special handling." );
947+
937948
/*
938949
* > A start tag whose tag name is one of: "area", "br", "embed", "img", "keygen", "wbr"
939950
*/
951+
case '+AREA':
952+
case '+BR':
953+
case '+EMBED':
940954
case '+IMG':
955+
case '+KEYGEN':
956+
case '+WBR':
941957
$this->reconstruct_active_formatting_elements();
942958
$this->insert_html_element( $this->state->current_token );
959+
$this->state->frameset_ok = false;
943960
return true;
944961
}
945962

@@ -966,13 +983,11 @@ private function step_in_body() {
966983
case 'BASEFONT':
967984
case 'BGSOUND':
968985
case 'BODY':
969-
case 'BR':
970986
case 'CAPTION':
971987
case 'COL':
972988
case 'COLGROUP':
973989
case 'DD':
974990
case 'DT':
975-
case 'EMBED':
976991
case 'FORM':
977992
case 'FRAME':
978993
case 'FRAMESET':
@@ -981,7 +996,6 @@ private function step_in_body() {
981996
case 'HTML':
982997
case 'IFRAME':
983998
case 'INPUT':
984-
case 'KEYGEN':
985999
case 'LI':
9861000
case 'LINK':
9871001
case 'LISTING':
@@ -1021,7 +1035,6 @@ private function step_in_body() {
10211035
case 'TR':
10221036
case 'TRACK':
10231037
case 'UL':
1024-
case 'WBR':
10251038
case 'XMP':
10261039
$this->last_error = self::ERROR_UNSUPPORTED;
10271040
throw new WP_HTML_Unsupported_Exception( "Cannot process {$tag_name} element." );

tests/phpunit/tests/html-api/wpHtmlProcessor.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,13 @@ public function test_step_in_body_fails_on_unsupported_tags( $tag_name ) {
159159
public function data_unsupported_special_in_body_tags() {
160160
return array(
161161
'APPLET' => array( 'APPLET' ),
162-
'AREA' => array( 'AREA' ),
163162
'BASE' => array( 'BASE' ),
164163
'BASEFONT' => array( 'BASEFONT' ),
165164
'BGSOUND' => array( 'BGSOUND' ),
166165
'BODY' => array( 'BODY' ),
167-
'BR' => array( 'BR' ),
168166
'CAPTION' => array( 'CAPTION' ),
169167
'COL' => array( 'COL' ),
170168
'COLGROUP' => array( 'COLGROUP' ),
171-
'EMBED' => array( 'EMBED' ),
172169
'FORM' => array( 'FORM' ),
173170
'FRAME' => array( 'FRAME' ),
174171
'FRAMESET' => array( 'FRAMESET' ),
@@ -177,7 +174,6 @@ public function data_unsupported_special_in_body_tags() {
177174
'HTML' => array( 'HTML' ),
178175
'IFRAME' => array( 'IFRAME' ),
179176
'INPUT' => array( 'INPUT' ),
180-
'KEYGEN' => array( 'KEYGEN' ),
181177
'LINK' => array( 'LINK' ),
182178
'LISTING' => array( 'LISTING' ),
183179
'MARQUEE' => array( 'MARQUEE' ),
@@ -214,7 +210,6 @@ public function data_unsupported_special_in_body_tags() {
214210
'TITLE' => array( 'TITLE' ),
215211
'TR' => array( 'TR' ),
216212
'TRACK' => array( 'TRACK' ),
217-
'WBR' => array( 'WBR' ),
218213
'XMP' => array( 'XMP' ),
219214
);
220215
}

tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,33 @@ public function test_in_body_any_other_end_tag_with_unclosed_non_special_element
376376
$this->assertSame( 'DIV', $p->get_tag(), "Expected to find DIV element, but found {$p->get_tag()} instead." );
377377
$this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' );
378378
}
379+
380+
/**
381+
* Verifies that when "in body" and encountering a br close tag `</br …>`:
382+
*
383+
* > An end tag whose tag name is "br"
384+
* > Parse error. Drop the attributes from the token, and act as described in the next entry;
385+
* > i.e. act as if this was a "br" start tag token with no attributes, rather than the end
386+
* > tag token that it actually is.
387+
*
388+
* @covers WP_HTML_Processor::step_in_body
389+
*
390+
* @ticket 58907
391+
*
392+
* @since 6.4.0
393+
*/
394+
public function test_br_close_tag_special_behavior() {
395+
$this->markTestIncomplete( 'BR end tag special handling is unimplemented' );
396+
397+
$p = WP_HTML_Processor::create_fragment( '</br attribute="must be removed">' );
398+
399+
$this->assertTrue( $p->next_tag( 'BR' ), 'No BR tag found.' );
400+
$this->assertNull( $p->get_attribute_names_with_prefix( '' ), 'BR end tag had attributes.' );
401+
$this->assertFalse( $p->is_tag_closer(), '</br> is treated as a BR start tag.' );
402+
403+
$this->assertFalse( $p->set_attribute( 'new-attribute', 'added' ), 'BR end tag becomes an opener' );
404+
$this->assertCount( 1, $p->get_attribute_names_with_prefix( '' ), 'Tag should have 1 attribute.' );
405+
$this->assertSame( 'added', $p->get_attribute( 'new-attribute' ), 'Tag did not set attribute value correctly.' );
406+
$this->assertSame( '<br new-attribute="added">', $p->get_updated_html(), 'Tag HTML was not updated correctly.' );
407+
}
379408
}

0 commit comments

Comments
 (0)