Skip to content

Commit d57744f

Browse files
committed
Continue updating patch.
1 parent 55e20cf commit d57744f

3 files changed

Lines changed: 50 additions & 33 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,13 +1373,15 @@ private function step_in_body() {
13731373
* > A start tag whose tag name is "iframe"
13741374
*/
13751375
case '+IFRAME':
1376+
$this->insert_html_element( $this->state->current_token );
13761377
$this->state->frameset_ok = false;
13771378
return true;
13781379

13791380
/*
13801381
* > A start tag whose tag name is "noembed"
13811382
*/
13821383
case '+NOEMBED':
1384+
$this->insert_html_element( $this->state->current_token );
13831385
return true;
13841386
}
13851387

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,23 @@ public function test_clear_to_navigate_after_seeking() {
112112
}
113113

114114
/**
115-
* Ensures that support is added for reconstructing active formatting elements
116-
* before the HTML Processor handles situations with unclosed formats requiring it.
115+
* Ensures that support is added for reconstructing active formatting elements.
117116
*
118117
* @ticket 58517
119118
*
120119
* @covers WP_HTML_Processor::reconstruct_active_formatting_elements
121120
*/
122-
public function test_fails_to_reconstruct_formatting_elements() {
123-
$processor = WP_HTML_Processor::create_fragment( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' );
121+
public function test_reconstructs_formatting_elements() {
122+
$processor = WP_HTML_Processor::create_fragment( '<p><em>One<p><em><span>Two<p><em>Three<p><em>Four' );
124123

125124
$this->assertTrue( $processor->next_tag( 'EM' ), 'Could not find first EM.' );
126-
$this->assertFalse( $processor->next_tag( 'EM' ), 'Should have aborted before finding second EM as it required reconstructing the first EM.' );
125+
$this->assertSame( array( 'HTML', 'BODY', 'P', 'EM' ), $processor->get_breadcrumbs(), 'Found incorrect breadcrumbs for first EM.' );
126+
$this->assertTrue( $processor->next_tag( 'SPAN' ), 'Could not find test span.' );
127+
$this->assertSame(
128+
array( 'HTML', 'BODY', 'P', 'EM', 'EM', 'SPAN' ),
129+
$processor->get_breadcrumbs(),
130+
'Found incorrect breadcrumbs for test SPAN; should have created two EMs.'
131+
);
127132
}
128133

129134
/**

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

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -224,45 +224,55 @@ public static function data_unsupported_elements() {
224224
}
225225

226226
/**
227-
* @ticket 58517
228-
*
229-
* @dataProvider data_unsupported_markup
227+
* Ensures that formats inside unclosed A elements are reconstructed.
230228
*
231-
* @param string $html HTML containing unsupported markup.
229+
* @ticket {TICKET_NUMBER}
232230
*/
233-
public function test_fails_when_encountering_unsupported_markup( $html, $description ) {
234-
$processor = WP_HTML_Processor::create_fragment( $html );
235-
236-
while ( $processor->next_token() && null === $processor->get_attribute( 'supported' ) ) {
237-
continue;
238-
}
231+
public function test_reconstructs_formatting_from_unclosed_a_elements() {
232+
$processor = WP_HTML_Processor::create_fragment( '<a><strong>Click <a><big>Here</big></a></strong></a>' );
239233

240-
$this->assertNull(
241-
$processor->get_last_error(),
242-
'Bailed on unsupported input before finding supported checkpoint: check test code.'
234+
$processor->next_tag( 'STRONG' );
235+
$this->assertSame(
236+
array( 'HTML', 'BODY', 'A', 'STRONG' ),
237+
$processor->get_breadcrumbs(),
238+
'Failed to construct starting breadcrumbs properly.'
243239
);
244240

245-
$this->assertTrue( $processor->get_attribute( 'supported' ), 'Did not find required supported element.' );
246-
$processor->next_token();
247-
$this->assertNotNull( $processor->get_last_error(), "Didn't properly reject unsupported markup: {$description}" );
241+
$processor->next_tag( 'BIG' );
242+
$this->assertSame(
243+
array( 'HTML', 'BODY', 'STRONG', 'A', 'BIG' ),
244+
$processor->get_breadcrumbs(),
245+
'Failed to reconstruct the active formatting elements after an unclosed A element.'
246+
);
248247
}
249248

250249
/**
251-
* Data provider.
250+
* Ensures that unclosed A elements are reconstructed.
252251
*
253-
* @return array[]
252+
* @ticket {TICKET_NUMBER}
254253
*/
255-
public static function data_unsupported_markup() {
256-
return array(
257-
'A with formatting following unclosed A' => array(
258-
'<a><strong>Click <span supported><a unsupported><big>Here</big></a></strong></a>',
259-
'Unclosed formatting requires complicated reconstruction.',
260-
),
254+
public function test_reconstructs_unclosed_a_elements() {
255+
$processor = WP_HTML_Processor::create_fragment( '<a><div><a></div></a>' );
261256

262-
'A after unclosed A inside DIV' => array(
263-
'<a><div supported><a unsupported></div></a>',
264-
'A is a formatting element, which requires more complicated reconstruction.',
265-
),
257+
$processor->next_tag( 'DIV' );
258+
$this->assertSame(
259+
array( 'HTML', 'BODY', 'DIV' ),
260+
$processor->get_breadcrumbs(),
261+
'Failed to construct breadcrumbs properly - the DIV should have closed the A element.'
262+
);
263+
264+
// When the DIV re-opens, it reconstructs an unclosed A, then the A in the text is a second A.
265+
$processor->next_tag( 'A' );
266+
$this->assertSame(
267+
array( 'HTML', 'BODY', 'DIV', 'A' ),
268+
'Failed to create proper breadcrumbs for recreated A element.'
269+
);
270+
271+
// This is the one that's second in the raw text.
272+
$processor->next_tag( 'A' );
273+
$this->assertSame(
274+
array( 'HTML', 'BODY', 'DIV', 'A' ),
275+
'Failed to create proper breadcrumbs for explicit A element - this A should have closed the reconstructed A.'
266276
);
267277
}
268278

0 commit comments

Comments
 (0)