@@ -165,45 +165,55 @@ public static function data_single_tag_of_supported_elements() {
165165 }
166166
167167 /**
168- * @ticket 58517
169- *
170- * @dataProvider data_unsupported_markup
168+ * Ensures that formats inside unclosed A elements are reconstructed.
171169 *
172- * @param string $html HTML containing unsupported markup.
170+ * @ticket 61576
173171 */
174- public function test_fails_when_encountering_unsupported_markup ( $ html , $ description ) {
175- $ processor = WP_HTML_Processor::create_fragment ( $ html );
176-
177- while ( $ processor ->next_token () && null === $ processor ->get_attribute ( 'supported ' ) ) {
178- continue ;
179- }
172+ public function test_reconstructs_formatting_from_unclosed_a_elements () {
173+ $ processor = WP_HTML_Processor::create_fragment ( '<a><strong>Click <a><big>Here</big></a></strong></a> ' );
180174
181- $ this ->assertNull (
182- $ processor ->get_last_error (),
183- 'Bailed on unsupported input before finding supported checkpoint: check test code. '
175+ $ processor ->next_tag ( 'STRONG ' );
176+ $ this ->assertSame (
177+ array ( 'HTML ' , 'BODY ' , 'A ' , 'STRONG ' ),
178+ $ processor ->get_breadcrumbs (),
179+ 'Failed to construct starting breadcrumbs properly. '
184180 );
185181
186- $ this ->assertTrue ( $ processor ->get_attribute ( 'supported ' ), 'Did not find required supported element. ' );
187- $ processor ->next_token ();
188- $ this ->assertNotNull ( $ processor ->get_last_error (), "Didn't properly reject unsupported markup: {$ description }" );
182+ $ processor ->next_tag ( 'BIG ' );
183+ $ this ->assertSame (
184+ array ( 'HTML ' , 'BODY ' , 'STRONG ' , 'A ' , 'BIG ' ),
185+ $ processor ->get_breadcrumbs (),
186+ 'Failed to reconstruct the active formatting elements after an unclosed A element. '
187+ );
189188 }
190189
191190 /**
192- * Data provider .
191+ * Ensures that unclosed A elements are reconstructed .
193192 *
194- * @return array[]
193+ * @ticket 61576
195194 */
196- public static function data_unsupported_markup () {
197- return array (
198- 'A with formatting following unclosed A ' => array (
199- '<a><strong>Click <span supported><a unsupported><big>Here</big></a></strong></a> ' ,
200- 'Unclosed formatting requires complicated reconstruction. ' ,
201- ),
195+ public function test_reconstructs_unclosed_a_elements () {
196+ $ processor = WP_HTML_Processor::create_fragment ( '<a><div><a></div></a> ' );
202197
203- 'A after unclosed A inside DIV ' => array (
204- '<a><div supported><a unsupported></div></a> ' ,
205- 'A is a formatting element, which requires more complicated reconstruction. ' ,
206- ),
198+ $ processor ->next_tag ( 'DIV ' );
199+ $ this ->assertSame (
200+ array ( 'HTML ' , 'BODY ' , 'DIV ' ),
201+ $ processor ->get_breadcrumbs (),
202+ 'Failed to construct breadcrumbs properly - the DIV should have closed the A element. '
203+ );
204+
205+ // When the DIV re-opens, it reconstructs an unclosed A, then the A in the text is a second A.
206+ $ processor ->next_tag ( 'A ' );
207+ $ this ->assertSame (
208+ array ( 'HTML ' , 'BODY ' , 'DIV ' , 'A ' ),
209+ 'Failed to create proper breadcrumbs for recreated A element. '
210+ );
211+
212+ // This is the one that's second in the raw text.
213+ $ processor ->next_tag ( 'A ' );
214+ $ this ->assertSame (
215+ array ( 'HTML ' , 'BODY ' , 'DIV ' , 'A ' ),
216+ 'Failed to create proper breadcrumbs for explicit A element - this A should have closed the reconstructed A. '
207217 );
208218 }
209219
0 commit comments