@@ -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