@@ -27,6 +27,11 @@ class Tests_HtmlApi_WpHtmlProcessorHtml5lib extends WP_UnitTestCase {
2727 'adoption01/line0046 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
2828 'adoption01/line0159 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
2929 'adoption01/line0318 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
30+ 'entities02/line0100 ' => 'Encoded characters without semicolon termination in attribute values are not handled properly ' ,
31+ 'entities02/line0114 ' => 'Encoded characters without semicolon termination in attribute values are not handled properly ' ,
32+ 'entities02/line0128 ' => 'Encoded characters without semicolon termination in attribute values are not handled properly ' ,
33+ 'entities02/line0142 ' => 'Encoded characters without semicolon termination in attribute values are not handled properly ' ,
34+ 'entities02/line0156 ' => 'Encoded characters without semicolon termination in attribute values are not handled properly ' ,
3035 'tests15/line0001 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
3136 'tests15/line0022 ' => 'Unimplemented: Reconstruction of active formatting elements. ' ,
3237 'tests20/line0497 ' => "Closing P tag implicitly creates opener, which we don't visit. " ,
@@ -118,14 +123,27 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
118123
119124 $ output = "<html> \n <head> \n <body> \n" ;
120125 while ( $ p ->next_tag () ) {
126+ $ indent = '' ;
127+
121128 // Breadcrumbs include this tag, so skip 1 nesting level.
122129 foreach ( $ p ->get_breadcrumbs () as $ index => $ _ ) {
123130 if ( $ index ) {
124- $ output .= ' ' ;
131+ $ indent .= ' ' ;
125132 }
126133 }
127134 $ t = strtolower ( $ p ->get_tag () );
128- $ output .= "< {$ t }> \n" ;
135+ $ output .= "{$ indent }< {$ t }> \n" ;
136+
137+ $ attribute_names = $ p ->get_attribute_names_with_prefix ( '' );
138+ sort ( $ attribute_names , SORT_STRING );
139+
140+ foreach ( $ attribute_names as $ attribute_name ) {
141+ $ val = $ p ->get_attribute ($ attribute_name );
142+ if ( $ val === true ) {
143+ $ val = "" ;
144+ }
145+ $ output .= "{$ indent } {$ attribute_name }= \"{$ val }\"\n" ;
146+ }
129147 }
130148
131149 if ( WP_HTML_Processor::ERROR_UNSUPPORTED === $ p ->get_last_error () ) {
@@ -226,7 +244,6 @@ public static function parse_html5_dat_testfile( $filename ) {
226244 * the root document node.
227245 */
228246 case 'document ' :
229- // Ignore everything that doesn't look like an element.
230247 if ( '| ' === $ line [0 ] ) {
231248 $ candidate = substr ( $ line , 2 );
232249 $ trimmed = trim ( $ candidate );
@@ -236,6 +253,13 @@ public static function parse_html5_dat_testfile( $filename ) {
236253 if ( strlen ( $ trimmed ) > 2 && '< ' === $ trimmed [0 ] && ctype_alpha ( $ trimmed [1 ] ) ) {
237254 $ test_dom .= $ candidate ;
238255 }
256+
257+ if (
258+ ( $ trimmed [0 ] !== '< ' || $ trimmed [ strlen ($ trimmed ) - 1 ] !== '> ' ) &&
259+ $ trimmed [0 ] !== '" '
260+ ) {
261+ $ test_dom .= $ candidate ;
262+ }
239263 }
240264 break ;
241265 }
0 commit comments