Skip to content

Commit 1eb1d21

Browse files
committed
Add "area", "br", "embed", "img", "keygen", "wbr" tag rules
1 parent 54a318e commit 1eb1d21

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
@@ -925,12 +925,29 @@ private function step_in_body() {
925925
$this->run_adoption_agency_algorithm();
926926
return true;
927927

928+
929+
/*
930+
* > An end tag whose tag name is "br"
931+
* > Parse error. Drop the attributes from the token, and act as described in the next
932+
* > entry; i.e. act as if this was a "br" start tag token with no attributes, rather
933+
* > than the end tag token that it actually is.
934+
*/
935+
case '-BR':
936+
$this->last_error = self::ERROR_UNSUPPORTED;
937+
throw new WP_HTML_Unsupported_Exception( "Closing BR tags require unimplemented special handling." );
938+
928939
/*
929940
* > A start tag whose tag name is one of: "area", "br", "embed", "img", "keygen", "wbr"
930941
*/
942+
case '+AREA':
943+
case '+BR':
944+
case '+EMBED':
931945
case '+IMG':
946+
case '+KEYGEN':
947+
case '+WBR':
932948
$this->reconstruct_active_formatting_elements();
933949
$this->insert_html_element( $this->state->current_token );
950+
$this->state->frameset_ok = false;
934951
return true;
935952
}
936953

@@ -957,13 +974,11 @@ private function step_in_body() {
957974
case 'BASEFONT':
958975
case 'BGSOUND':
959976
case 'BODY':
960-
case 'BR':
961977
case 'CAPTION':
962978
case 'COL':
963979
case 'COLGROUP':
964980
case 'DD':
965981
case 'DT':
966-
case 'EMBED':
967982
case 'FORM':
968983
case 'FRAME':
969984
case 'FRAMESET':
@@ -972,7 +987,6 @@ private function step_in_body() {
972987
case 'HTML':
973988
case 'IFRAME':
974989
case 'INPUT':
975-
case 'KEYGEN':
976990
case 'LI':
977991
case 'LINK':
978992
case 'LISTING':
@@ -1012,7 +1026,6 @@ private function step_in_body() {
10121026
case 'TR':
10131027
case 'TRACK':
10141028
case 'UL':
1015-
case 'WBR':
10161029
case 'XMP':
10171030
$this->last_error = self::ERROR_UNSUPPORTED;
10181031
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)